QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788843 | #7588. Monster Hunter | KFC | WA | 1053ms | 18796kb | C++23 | 1.2kb | 2024-11-27 18:30:04 | 2024-11-27 18:30:08 |
Judging History
answer
// Hydro submission #6746f4a99592d6097b86b523@1732703402567
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[100010],b[100010],p[100010],fa[100010];
vector<int> g[100010];
struct Node{
int u,a,b;
friend bool operator<(Node x,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;
}
};
priority_queue<Node> pq;
void dfs(int u,int fat)
{
fa[u]=fat;
for(int v:g[u])if(v!=fat)dfs(v,u);
}
int find(int x)
{
if(p[x]!=x)p[x]=find(p[x]);
return p[x];
}
void solve()
{
int i;
cin>>n;
for(i=1;i<=n;i++)p[i]=i,g[i].clear();
for(i=2;i<=n;i++)cin>>a[i]>>b[i];
for(i=1;i<n;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b),g[b].push_back(a);
}
dfs(1,0);
for(i=2;i<=n;i++)pq.push({i,a[i],b[i]});
while(pq.size()){
Node x=pq.top();
pq.pop();
if(x.u==1||a[x.u]!=x.a||b[x.u]!=x.b||find(x.u)!=x.u)continue;
int u=x.u,v=find(fa[u]),c=max(a[v],a[u]+a[v]-b[v]),d=c-a[u]+b[u]-a[v]+b[v];
p[u]=v,a[v]=c,b[v]=d,pq.push({v,a[v],b[v]});
}
cout<<a[1]<<'\n';
}
signed main()
{
int _;cin>>_;
while(_--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7636kb
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: 1053ms
memory: 18796kb
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 604652243 796269298 796269298 796269298 796269298 796269298 796269298 796269298 796269298
result:
wrong answer 2nd numbers differ - expected: '541156749', found: '604652243'