QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#403977 | #7588. Monster Hunter | kevinyang | WA | 336ms | 22564kb | C++17 | 1.2kb | 2024-05-03 01:11:25 | 2024-05-03 01:11:25 |
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-=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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8608kb
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: 336ms
memory: 22564kb
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:
3740265354 29219492149 1731255967736 868611963155 2638816228492 6617628987427 7753394190496 4575085355005 122474168778 1919199988424
result:
wrong answer 1st numbers differ - expected: '63495498', found: '3740265354'