QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403985 | #7588. Monster Hunter | kevinyang | WA | 336ms | 11440kb | C++17 | 1.6kb | 2024-05-03 01:36:34 | 2024-05-03 01:36:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mxn = 100005;
// Comparator struct for comparing two pii pairs
struct Comp {
bool operator()(const pii& a, const pii& b) const {
return max(a.first, -a.second + a.first + b.first) < max(b.first, -b.second + b.first + a.first);
}
};
// Comparator for the priority_queue that contains a pair of pii and int
struct Cmp {
bool operator()(const pair<pii, int>& a, const pair<pii, int>& b) const {
Comp comp;
return comp(a.first, b.first);
}
};
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<int>> adj(n+1);
vector<bool> vis(n+1);
priority_queue<pair<pii, int>, vector<pair<pii, int>>, Cmp> pq;
vector<int>a(n+1);
vector<int>b(n+1);
for(int i = 2; i<=n; i++){
cin >> a[i] >> b[i];
}
for(int i = 2; i<=n; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
vis[1] = true;
pq.push({{a[1],b[1]},1});
int rq = 0;
int ans = 0;
while(pq.size()){
auto [p,i] = pq.top();
pq.pop();
rq+=p.first;
ans = max(ans,rq);
rq-=p.second;
for(int nxt: adj[i]){
if(vis[nxt])continue;
vis[nxt] = true;
pq.push({{a[nxt],b[nxt]},nxt});
}
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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: 11440kb
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:
119426649 1366713167 38094229042 1488736956450 370349773161 166612972790 139664010002 151324291179 1278017243079 689680360394
result:
wrong answer 1st numbers differ - expected: '63495498', found: '119426649'