QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788346 | #7588. Monster Hunter | konata2828 | WA | 1ms | 7596kb | C++23 | 1.1kb | 2024-11-27 16:37:47 | 2024-11-27 16:37:49 |
Judging History
answer
// Hydro submission #6746da599592d6097b868d46@1732696666034
#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];
}
signed main()
{
int i;
cin>>n;
for(i=2;i<=n;i++)cin>>a[i]>>b[i];
for(i=1;i<=n;i++)p[i]=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];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7596kb
input:
1 4 2 6 5 4 6 2 1 2 2 3 3 4
output:
0
result:
wrong answer 1st numbers differ - expected: '3', found: '0'