QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226009#7588. Monster Hunterucup-team004#WA 880ms20460kbC++201.8kb2023-10-25 14:26:282023-10-25 14:26:28

Judging History

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

  • [2023-10-25 14:26:28]
  • 评测
  • 测评结果:WA
  • 用时:880ms
  • 内存:20460kb
  • [2023-10-25 14:26:28]
  • 提交

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.b>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;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 6988kb

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: 880ms
memory: 20460kb

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'