QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788295 | #7588. Monster Hunter | KFC | Compile Error | / | / | C++98 | 1.5kb | 2024-11-27 16:27:16 | 2024-11-27 16:27:23 |
Judging History
answer
// Hydro submission #6746d7e09592d6097b868852@1732696033131
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int T,n;
int a[N],b[N];
vector<int> g[N];
int f[N],fa[N];
int get(int x) {
if(fa[x]==x) return x;
return fa[x]=get(fa[x]);
}
void dfs(int u,int fa) {
f[u]=fa;
for(int v:g[u]) {
if(v==fa) continue;
dfs(v,u);
}
}
struct Node{
ll a,b;
}nd[N];
bool operator<(Node u,Node v) {
if(u.b>0 && v.b>0) return u.a>v.a;
else if(u.b<=0 && v.b<=0) return u.a+u.b<v.a+v.b;
return u.b<0;
}
bool operator!=(Node u,Node v) {
return u.a!=v.a || u.b!=v.b;
}
Node operator+(Node u,Node v) {
u.a=max(u.a,v.a-u.b);
u.b+=v.b;
return u;
}
priority_queue<pair<Node,int> > q;
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=1;i<=n;i++) g[i].clear();
nd[1]={0,0};
for(int i=2;i<=n;i++) {
scanf("%d%d",&a[i],&b[i]);
b[i]-=a[i];
nd[i]={a[i],b[i]};
q.push({nd[i],i});
}
for(int i=1;i<n;i++) {
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v),g[v].push_back(u);
}
dfs(1,0);
for(int i=1;i<=n;i++) fa[i]=i;
while(!q.empty()) {
int u=q.top().second;
if(q.top().first!=nd[u]) {
q.pop();
continue;
}
q.pop();
int v=get(f[u]);
fa[u]=f[u];
nd[v]=nd[v]+nd[u];
if(v!=1) q.push({nd[v],v});
}
printf("%lld\n",nd[1].a);
}
return 0;
}
Details
answer.code: In function ‘void dfs(int, int)’: answer.code:19:19: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 19 | for(int v:g[u]) { | ^ answer.code:19:22: error: forming reference to reference type ‘std::vector<int>&’ 19 | for(int v:g[u]) { | ^ answer.code: In function ‘int main()’: answer.code:52:23: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 52 | nd[1]={0,0}; | ^ answer.code:52:23: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] answer.code:56:33: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 56 | nd[i]={a[i],b[i]}; | ^ answer.code:56:33: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] answer.code:57:24: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 57 | q.push({nd[i],i}); | ^ answer.code:57:23: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 57 | q.push({nd[i],i}); | ~~~~~~^~~~~~~~~~~ answer.code:76:33: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 76 | if(v!=1) q.push({nd[v],v}); | ^ answer.code:76:32: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions] 76 | if(v!=1) q.push({nd[v],v}); | ~~~~~~^~~~~~~~~~~ answer.code:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%d",&T); | ~~~~~^~~~~~~~~ answer.code:50:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%d",&n); | ~~~~~^~~~~~~~~ answer.code:54:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | scanf("%d%d",&a[i],&b[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~ answer.code:61:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%d%d",&u,&v); | ~~~~~^~~~~~~~~~~~~~