QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771711#7588. Monster Huntertarjen#WA 521ms39340kbC++202.0kb2024-11-22 15:12:302024-11-22 15:12:32

Judging History

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

  • [2024-11-22 15:12:32]
  • 评测
  • 测评结果:WA
  • 用时:521ms
  • 内存:39340kb
  • [2024-11-22 15:12:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2>
ostream& operator << (ostream& out,pair<T1,T2> p) {
    out<<"("<<p.first<<","<<p.second<<")";
    return out;
}
typedef long long ll;
struct info{
    ll a,b;
    bool operator<(info x)const{
        if((a<=b)^(x.a<=x.b))return a<=b;
        if(a<=b){
            if(a==x.a)return b<x.b;
            return a<x.a;
        }
        else {
            if(b==x.b)return a>x.a;
            return b>x.b;
        }
    };
    bool operator==(info x)const{
        return a==x.a&&b==x.b;
    };
    bool operator>(info x)const{
        return !(*this<x||*this==x);
    }
};
info operator+(info x,info y){
    if(x.b>=y.a){
        x.b-=y.a;
        x.b+=y.b;
        return x;
    }
    else{
        x.a-=x.b;
        x.a+=y.a;
        x.b+=y.b;
        return x;
    }
};
ll solve()
{
    int n;cin>>n;
    vector<ll>a(n+1),b(n+1);
    for(int i=2;i<=n;i++)cin>>a[i]>>b[i];
    vector<vector<int>> ve(n+1);
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        ve[x].push_back(y);
        ve[y].push_back(x);
    }
    vector<multiset<info>> s(n+1);
    auto merge= [&](multiset<info>&a,multiset<info>&b){// b-->a;
        if(b.size()>a.size())swap(a,b);
        for(auto it:b)a.insert(it);
    };
    function<void(int,int)> dfs= [&](int x,int h){
        for(auto it:ve[x])if(it!=h){
            dfs(it,x);
            merge(s[x],s[it]);
        }
        info now{a[x],b[x]};
        while(!s[x].empty()&&now>*s[x].begin()){
            now=now+(*s[x].begin());
            s[x].erase(s[x].begin());
        }
        s[x].insert(now);
        // cout<<"x="<<x<<endl;
        // for(auto it:s[x])cout<<make_pair(it.a,it.b)<<" ";;cout<<endl;
    };
    dfs(1,0);
    info now{0,0};
    for(auto it:s[1])now=now+it;
    return now.a;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 521ms
memory: 39340kb

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:

830850
6546895
191617241
177090559
383609891
992987677
505892074
540467851
84584890
84657366

result:

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