QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789224#7588. Monster HunterxxzxWA 433ms15384kbC++171.4kb2024-11-27 19:35:512024-11-27 19:35:52

Judging History

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

  • [2024-11-27 19:35:52]
  • 评测
  • 测评结果:WA
  • 用时:433ms
  • 内存:15384kb
  • [2024-11-27 19:35:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define clo 1000.*clock()/CLOCKS_PER_SEC
#ifndef xxzx
#define endl '\n'
#endif
using ll=long long;
using PII=pair<int,int>;
const int N=1e5+10;
bool memory1;
int n;
ll a[N],b[N];
vector<int> eg[N];
struct cmp {
    bool operator()(const int &x,const int &y) {
        if((a[x]<=b[x])!=(a[y]<=b[y])) return (a[x]>b[x]);
        if(a[x]<=b[x]) return a[x]>a[y];
        return b[x]<b[y];
    }
};
int fa[N];
void dfs(int x) {
    for(auto y:eg[x]) if(y!=fa[x]) fa[y]=x,dfs(y);
}
int f[N];
int find(int x) { return (x==f[x])? x:f[x]=find(f[x]); }
void solve() {
    cin>>n;
    priority_queue<int,vector<int>,cmp> q;
    for(int i=1;i<=n;i++) eg[i].clear(),f[i]=i;
    for(int i=2;i<=n;i++) cin>>a[i]>>b[i],q.push(i);
    for(int i=1,x,y;i<n;i++) cin>>x>>y,eg[x].push_back(y),eg[y].push_back(x);
    dfs(1);
    while(q.size()) {
        int x=q.top(); q.pop();
        int y=find(fa[x]);
        ll w=-a[x]+b[x]-a[y]+b[y];
        a[y]=max(a[y],a[x]-(-a[y]+b[y]));
        b[y]=w+a[y];
        f[x]=y;
    }
    cout<<a[1]<<endl;
}
bool memory2;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    int T; cin>>T;
    // int T=1;
    while(T--) solve();

    #ifdef xxzx
    cerr<<"Time: "<<clo<<"MS"<<endl;
    cerr<<"Memory: "<<abs(&memory1-&memory2)/1024./1024.<<"MB"<<endl;
    #endif
    return 0;
}

詳細信息

Test #1:

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

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: 433ms
memory: 15384kb

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'