QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226000#7588. Monster Hunterucup-team004#WA 778ms20696kbC++201.8kb2023-10-25 14:19:212023-10-25 14:19:22

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 14:19:22]
  • 评测
  • 测评结果:WA
  • 用时:778ms
  • 内存:20696kb
  • [2023-10-25 14:19:21]
  • 提交

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: 8228kb

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: 778ms
memory: 20696kb

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:

4423117517
31897809624
1789402693399
11784386292719
11784386292719
11784386292719
11784386292719
11784386292719
11784386292719
11784386292719

result:

wrong answer 1st numbers differ - expected: '63495498', found: '4423117517'