QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790192 | #7588. Monster Hunter | KFC | Compile Error | / | / | C++98 | 2.6kb | 2024-11-28 07:48:11 | 2024-11-28 07:48:12 |
Judging History
This is the latest submission verdict.
- [2024-11-28 07:48:12]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-28 07:48:11]
- Submitted
answer
// Hydro submission #6747afb89592d6097b871639@1732751289707
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define N 100009
#define LL long long
#define pii pair<int,int>
using namespace std;
int n,idx=1,h[N],eg[N*2],ne[N*2],fa[N],die[N];
int tim[N];
LL a[N],b[N];
struct node1{
LL a,b;
int t,id;
bool operator<(const node1 c)const{
return a>c.a;
}
};
struct node2{
LL a,b;
int t,id;
bool operator<(const node2 c)const{
return b<c.b;
}
};
priority_queue<node1> q1;
priority_queue<node2> q2;
void add(int a,int b){
++idx,eg[idx]=b,ne[idx]=h[a],h[a]=idx;
}
void dfs(int u){
for(int y,i=h[u];i;i=ne[i]){
y=eg[i];
if(y==die[u]) continue;
die[y]=u;
dfs(y);
}
}
int find(int u){
if(fa[u]==u) return u;
return fa[u]=find(fa[u]);
}
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;i++) fa[i]=i,tim[i]=h[i]=0;
idx=1;
for(int i=2;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);
for(int a,b,i=1;i<n;i++){
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
}
dfs(1);
for(int i=1;i<=n;i++){
if(a[i]<=b[i]) q1.push({a[i],b[i],0,i});
else q2.push({a[i],b[i],0,i});
}
int tot=0;
while(q1.size() || q2.size()){
if(q1.size()){
node1 u=q1.top();
q1.pop();
if(u.t<tim[u.id]) continue;
int y=find(u.id);
if(y>1){
int t=find(die[y]);
fa[y]=t;
LL mb=-a[t]+b[t]-a[y]+b[y];
a[t]=-min(-a[t],-a[t]+b[t]-a[y]);
b[t]=mb+a[t];
tim[t]=++tot;
if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
else q2.push({a[t],b[t],tot,t});
}
}else{
node2 u=q2.top();
q2.pop();
if(u.t<tim[u.id]) continue;
int y=find(u.id);
if(y>1){
int t=find(die[y]);
fa[y]=t;
LL mb=-a[t]+b[t]-a[y]+b[y];
a[t]=-min(-a[t],-a[t]+b[t]-a[y]);
b[t]=mb+a[t];
tim[t]=++tot;
if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
else q2.push({a[t],b[t],tot,t});
}
}
}
printf("%lld",a[1]);
}
int main() {
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++) solve();
// freopen("tree.in","r",stdin);
// freopen("tree.out","w",stdout);
return 0;
}
Details
answer.code: In function ‘void solve()’: answer.code:47:5: error: ‘scanf’ was not declared in this scope; did you mean ‘wscanf’? 47 | scanf("%d",&n); | ^~~~~ | wscanf answer.code:58:32: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 58 | if(a[i]<=b[i]) q1.push({a[i],b[i],0,i}); | ^ answer.code:58:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 58 | if(a[i]<=b[i]) q1.push({a[i],b[i],0,i}); | ~~~~~~~^~~~~~~~~~~~~~~~~ answer.code:59:22: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 59 | else q2.push({a[i],b[i],0,i}); | ^ answer.code:59:21: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 59 | else q2.push({a[i],b[i],0,i}); | ~~~~~~~^~~~~~~~~~~~~~~~~ answer.code:75:40: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 75 | if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t}); | ^ answer.code:75:39: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 75 | if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t}); | ~~~~~~~^~~~~~~~~~~~~~~~~~~ answer.code:76:30: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 76 | else q2.push({a[t],b[t],tot,t}); | ^ answer.code:76:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 76 | else q2.push({a[t],b[t],tot,t}); | ~~~~~~~^~~~~~~~~~~~~~~~~~~ answer.code:90:40: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 90 | if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t}); | ^ answer.code:90:39: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 90 | if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t}); | ~~~~~~~^~~~~~~~~~~~~~~~~~~ answer.code:91:30: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 91 | else q2.push({a[t],b[t],tot,t}); | ^ answer.code:91:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 91 | else q2.push({a[t],b[t],tot,t}); | ~~~~~~~^~~~~~~~~~~~~~~~~~~ answer.code:95:5: error: ‘printf’ was not declared in this scope 95 | printf("%lld",a[1]); | ^~~~~~ answer.code:7:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’? 6 | #include<queue> +++ |+#include <cstdio> 7 | answer.code: In function ‘int main()’: answer.code:99:5: error: ‘scanf’ was not declared in this scope; did you mean ‘wscanf’? 99 | scanf("%d",&t); | ^~~~~ | wscanf