QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225996#7588. Monster Hunterucup-team004#WA 650ms20688kbC++201.8kb2023-10-25 14:17:322023-10-25 14:17:33

Judging History

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

  • [2023-10-25 14:17:33]
  • 评测
  • 测评结果:WA
  • 用时:650ms
  • 内存:20688kb
  • [2023-10-25 14:17:32]
  • 提交

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>0,fb=b.b>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;
    }
}

詳細信息

Test #1:

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

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: 650ms
memory: 20688kb

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:

3459047496
24653475630
1348610538436
9455751722716
9455751722716
9455751722716
9455751722716
9455751722716
9455751722716
9455751722716

result:

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