QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789041 | #7588. Monster Hunter | xxzx | WA | 406ms | 15084kb | C++17 | 1.5kb | 2024-11-27 19:08:56 | 2024-11-27 19:08:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define clo 1000.*clock()/CLOCKS_PER_SEC
#ifndef xxzx
#define endl '\n'
#endif
using ll=long long;
using PII=pair<int,int>;
const int N=1e5+10;
bool memory1;
int n;
ll a[N],b[N];
vector<int> eg[N];
struct cmp {
bool operator()(const int &x,const int &y) {
if((a[x]<=b[x])!=(a[y]<=b[y])) return (a[x]>b[x]);
if(a[x]<=b[x]) return a[x]>a[y];
return b[x]<b[y];
}
};
int fa[N];
void dfs(int x) {
for(auto y:eg[x]) if(y!=fa[x]) fa[y]=x,dfs(y);
}
int f[N];
int find(int x) { return (x==f[x])? x:f[x]=find(f[x]); }
void solve() {
cin>>n;
priority_queue<int,vector<int>,cmp> q;
for(int i=1;i<=n;i++) eg[i].clear(),f[i]=i;
for(int i=2;i<=n;i++) cin>>a[i]>>b[i],q.push(i);
for(int i=1,x,y;i<n;i++) cin>>x>>y,eg[x].push_back(y),eg[y].push_back(x);
dfs(1);
ll v1=0,v2=0;
while(q.size()) {
int x=q.top(); q.pop();
int y=find(fa[x]);
if(y!=1) {
ll w=-a[x]+b[x]-a[y]+b[y];
a[y]=max(a[y],a[x]-(-a[y]+b[y]));
b[y]=w+a[y];
}
else {
v2=max(v2,a[x]-v1);
v1=v1-a[x]+b[x];
}
f[x]=y;
}
cout<<v2<<endl;
}
bool memory2;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int T; cin>>T;
while(T--) solve();
#ifdef xxzx
cerr<<"Time: "<<clo<<"MS"<<endl;
cerr<<"Memory: "<<abs(&memory1-&memory2)/1024./1024.<<"MB"<<endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7712kb
input:
1 4 2 6 5 4 6 2 1 2 2 3 3 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 406ms
memory: 15084kb
input:
10 50000 112474 198604 847262 632597 871374 962220 971398 284540 10360 695245 43233 569941 64019 203468 598469 997911 41841 657552 333198 936119 546370 180011 58831 901040 959767 396595 710441 277461 429299 209831 494164 138327 393982 581911 993164 617488 108113 160310 55841 611360 301395 291074 149...
output:
63495498 541156749 191617241 177090559 630213926 27231993394 19064806867 37194996614 84584890 84657366
result:
wrong answer 5th numbers differ - expected: '383609891', found: '630213926'