QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403979 | #7588. Monster Hunter | kevinyang | WA | 297ms | 26268kb | C++17 | 1.3kb | 2024-05-03 01:15:45 | 2024-05-03 01:15:45 |
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]});
}
int rq = a[u];
int cur = a[u]-b[u];
vector<pii>vals2;
for(auto [x,y]: vals){
if(x<=rq && y>=0){
cur-=y;
}
else{
vals2.push_back({x,y});
}
}
sort(vals2.begin(),vals2.end(),comp);
for(auto [x,y] : vals2){
cur+=x;
rq = max(rq,cur);
cur-=x;
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: 8596kb
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: 297ms
memory: 26268kb
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 541157617 191617241 177090559 383609891 27232342028 19065024046 37196811824 241991055 84657366
result:
wrong answer 2nd numbers differ - expected: '541156749', found: '541157617'