QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403975 | #7588. Monster Hunter | kevinyang | WA | 286ms | 22704kb | C++17 | 1.2kb | 2024-05-03 01:08:07 | 2024-05-03 01:08:08 |
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.first - a.second + b.first) < max(b.first, 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: 3ms
memory: 8540kb
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: 286ms
memory: 22704kb
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:
8418026985 58165043434 1929036586840 10586359198759 10499583780018 10412513136149 5654742666056 3065977643699 13941747214576 15532661498918
result:
wrong answer 1st numbers differ - expected: '63495498', found: '8418026985'