QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226002 | #7588. Monster Hunter | ucup-team004# | WA | 788ms | 20584kb | C++20 | 1.8kb | 2023-10-25 14:20:30 | 2023-10-25 14:20:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
vector<int> v[N];
int n,fa[N],f[N];
struct dat{
ll a,b;
}a[N];
bool operator <(dat a,dat b){
int fa=a.b-a.a>0,fb=b.b-b.a>0;
return fa!=fb?fa>fb:(fa>0?a.a<b.a:a.a+a.b>b.a+b.b);
}
bool operator ==(dat a,dat b){
return a.a==b.a&&a.b==b.b;
}
dat operator +(dat a,dat b){
dat c;
c.a=max(a.a,a.a-a.b+b.a);
c.b=a.b+b.b-a.a-b.a+c.a;
//cerr<<c.a<<" wzp "<<c.b<<endl;
return c;
}
void dfs(int p){
for(auto i:v[p])if(i!=fa[p]){fa[i]=p; dfs(i);}
}
int gf(int x){
return f[x]==x?x:f[x]=gf(f[x]);
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t ;
cin>>t;
while(t--){
cin>>n;
For(i,1,n)v[i].clear();
f[1]=1;
set<pair<dat,int> > q;
For(i,2,n){
cin>>a[i].a>>a[i].b;
q.insert(mp(a[i],i));
f[i]=i;
}
For(i,1,n-1){
int s,t;
cin>>s>>t;
v[s].pb(t); v[t].pb(s);
}
dfs(1);
while(q.size()){
auto t=*q.begin(); q.erase(q.begin());
//cerr<<t.second<<" "<<endl; //if(t.second==0)return 0;
if(t.first==a[t.second]){
int y=t.second;
//cerr<<fa[y]<<" "<<gf(fa[y])<<endl;
int x=gf(fa[y]);
f[y]=x;
if(x!=1)q.erase(mp(a[x],x));
a[x]=a[x]+a[y];
if(x!=1)q.insert(mp(a[x],x));
}else{
assert(0);
continue;
}
}
cout<<a[1].a<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7668kb
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: 788ms
memory: 20584kb
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:
63501373 604653370 796269298 796269298 796269298 796269298 796269298 796269298 796269298 796269298
result:
wrong answer 1st numbers differ - expected: '63495498', found: '63501373'