QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788124#7588. Monster HunterliujiamengWA 0ms9148kbC++141.1kb2024-11-27 16:00:082024-11-27 16:00:45

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 16:00:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9148kb
  • [2024-11-27 16:00:08]
  • 提交

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'