QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788124 | #7588. Monster Hunter | liujiameng | WA | 0ms | 9148kb | C++14 | 1.1kb | 2024-11-27 16:00:08 | 2024-11-27 16:00:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
vector<int>g[N];
int a[N], b[N], fa[N], f[N];
int find(int x){return x == f[x] ? x : f[x] = find(f[x]);}
void dfs(int x, int f)
{
fa[x] = f;
for(auto j:g[x]) if(j!=f) dfs(j,x);
}
struct ab{int a,b,id;};
bool operator < (const ab &a, const ab &b)
{
int va = (a.a <= a.b), vb = (b.a <= b.b);
if(va!=vb) return va < vb;
if(!va) return a.b < b.b;
return a.a > b.a;
}
priority_queue<ab>pq;
signed main()
{
int n, i, u, v;
scanf("%lld", &n);
for(i=1;i<=n;i++) f[i] = i;
for(i=2;i<=n;i++) scanf("%lld%lld", &a[i], &b[i]);
for(i=1;i<n;i++) scanf("%lld%lld", &u, &v), g[u].emplace_back(v), g[v].emplace_back(u);
dfs(1,0);
for(i=2;i<=n;i++) pq.push({a[i],b[i],i});
while(!pq.empty())
{
ab t = pq.top();pq.pop();
int d = t.id;
if(t.a!=a[d]||t.b!=b[d]) continue;
int f = find(fa[d]);
int ab = b[f] + b[d] - a[f] - a[d];
a[f] = max(a[f],a[f]-b[f]+a[d]), b[f] = a[f] + ab;
if(f!=1) pq.push({a[f],b[f],f});
::f[d] = f;
}
printf("%lld", a[1]);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9148kb
input:
1 4 2 6 5 4 6 2 1 2 2 3 3 4
output:
0
result:
wrong answer 1st numbers differ - expected: '3', found: '0'