QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787976 | #7588. Monster Hunter | KFC | Compile Error | / | / | C++98 | 1.6kb | 2024-11-27 15:27:41 | 2024-11-27 15:27:47 |
Judging History
answer
// Hydro submission #6746c9eb9592d6097b86653c@1732692460042
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll a[100001],b[100001];
vector<int> E[100001];
int p[100001],fa[100001];
void init(int u,int father){
p[u]=father;
for(int v :E[u])if(v!=father)init(v,u);
}
int find(int x){
if(fa[x]==x)return x;
else return fa[x]=find(fa[x]);
}
struct Node{
int u;
ll a,b;
Node(int _u,ll _a,ll _b):u(_u),a(_a),b(_b){}
friend bool operator<(const Node x,const Node y){
if((x.a<x.b)!=(y.a<y.b))return y.a<y.b;
return x.a<x.b?x.a>y.a:x.b<y.b;
// x.b < y.b <===> max(x.a,x.a+y.a-x.b) > max(y.a,x.a+y.a-y.b)
}
};
int main(){
int T; scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=2;i<=n;i++)scanf("%lld%lld",a+i,b+i);
for(int i=1;i<=n;i++)fa[i]=i,E[i].clear();
for(int i=1;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
E[u].push_back(v);
E[v].push_back(u);
}
a[1]=b[1]=0;
init(1,0);
priority_queue<Node> Q;
for(int i=2;i<=n;i++)Q.emplace(i,a[i],b[i]);
while(!Q.empty()){
Node node=Q.top(); Q.pop();
if(node.u==1||a[node.u]!=node.a||b[node.u]!=node.b||find(node.u)!=node.u)continue;
int u=node.u,v=find(p[u]);
ll newa=max(a[v],a[u]+a[v]-b[v]);
ll newb=newa-a[u]+b[u]-a[v]+b[v];
fa[u]=v,a[v]=newa,b[v]=newb,Q.emplace(v,a[v],b[v]);
}
printf("%lld\n",a[1]);
}
return 0;
}
Details
answer.code: In function ‘void init(int, int)’: answer.code:13:16: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 13 | for(int v :E[u])if(v!=father)init(v,u); | ^ answer.code:13:19: error: forming reference to reference type ‘std::vector<int>&’ 13 | for(int v :E[u])if(v!=father)init(v,u); | ^ answer.code: In function ‘int main()’: answer.code:46:32: error: ‘class std::priority_queue<Node>’ has no member named ‘emplace’ 46 | for(int i=2;i<=n;i++)Q.emplace(i,a[i],b[i]); | ^~~~~~~ answer.code:53:43: error: ‘class std::priority_queue<Node>’ has no member named ‘emplace’ 53 | fa[u]=v,a[v]=newa,b[v]=newb,Q.emplace(v,a[v],b[v]); | ^~~~~~~ answer.code:32:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | int T; scanf("%d",&T); | ~~~~~^~~~~~~~~ answer.code:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d",&n); | ~~~~~^~~~~~~~~ answer.code:35:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | for(int i=2;i<=n;i++)scanf("%lld%lld",a+i,b+i); | ~~~~~^~~~~~~~~~~~~~~~~~~~ answer.code:39:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d%d",&u,&v); | ~~~~~^~~~~~~~~~~~~~