QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403976 | #7588. Monster Hunter | kevinyang | WA | 323ms | 22660kb | C++17 | 1.2kb | 2024-05-03 01:10:50 | 2024-05-03 01:10:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mxn = 100005;
vector<vector<int>>adj(mxn);
vector<int>dp(mxn);
vector<int>sum(mxn);
vector<int>a(mxn);
vector<int>b(mxn);
bool comp(pii a, pii b){
return max(a.first, a.second + b.first) < max(b.first, b.second + a.first);
}
void dfs(int u, int p){
vector<pii>vals;
sum[u] = b[u]-a[u];
for(int nxt: adj[u]){
if(nxt==p)continue;
dfs(nxt,u);
sum[u]+=sum[nxt];
vals.push_back({dp[nxt],sum[nxt]});
}
sort(vals.begin(),vals.end(),comp);
int rq = a[u];
int cur = a[u]-b[u];
for(auto [x,y] : vals){
cur+=x;
rq = max(rq,cur);
cur-=y;
}
dp[u] = rq;
}
void reset(int n){
for(int i = 1; i<=n; i++){
adj[i].clear();
dp[i] = sum[i] = a[i] = b[i] = 0;
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i = 2; i<=n; i++){
cin >> a[i] >> b[i];
}
for(int i = 1; i<n; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(1,0);
cout << dp[1] << '\n';
reset(n);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8520kb
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: 323ms
memory: 22660kb
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:
237972263877 2389581337084 55759234267069 38795650811459 50152316506494 138721750096137 124597623347041 67869702458279 40457842578781 50613877395605
result:
wrong answer 1st numbers differ - expected: '63495498', found: '237972263877'