QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787993#7588. Monster Hunterkonata2828WA 1ms8168kbC++171.4kb2024-11-27 15:30:372024-11-27 15:30:38

Judging History

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

  • [2024-11-27 15:30:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8168kb
  • [2024-11-27 15:30:37]
  • 提交

answer

// Hydro submission #6746ca9b9592d6097b86679c@1732692636465
#include<bits/stdc++.h>
using namespace std;
namespace ax_by_c{
typedef long long ll;
const int N=1e5+5;
int n;
ll a[N],b[N];
vector<int>g[N];
int fa[N];
void dfs(int u){
	for(auto v:g[u]){
		if(v==fa[u])continue;
		fa[v]=u;
		dfs(v);
	}
}
struct node{
	int u;
	ll a,b;
	bool operator < (const node& y)const{
		if(b-a>=0&&y.b-y.a<0)return 0;
		if(b-a<0&&y.b-y.a>=0)return 1;
		if(b-a>=0)return a>y.a;
		else return b<y.b;
	}
};
bool vis[N];
int find(int u){
	if(!vis[u])return u;
	return fa[u]=find(fa[u]);
}
void main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]);
	for(int i=1,x,y;i<n;i++){
		scanf("%d %d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1);
	priority_queue<node>pq;
	for(int i=2;i<=n;i++)pq.push({i,a[i],b[i]});
	ll ans=0,cur=0;
	while(pq.size()){
		auto tmp=pq.top();
		pq.pop();
		if(vis[tmp.u]||a[tmp.u]!=tmp.a||b[tmp.u]!=tmp.b)continue;
		vis[tmp.u]=1;
		int pos=find(tmp.u);
		if(pos==1){
			if(cur<tmp.a){
				ans+=tmp.a-cur;
				cur=tmp.a;
			}
			cur-=tmp.a;
			cur+=tmp.b;
		}
		else{
			ll ttmp=max(a[pos],a[pos]-b[pos]+tmp.a);
			b[pos]=b[pos]-a[pos]+tmp.b-tmp.a+ttmp;
			a[pos]=ttmp;
			pq.push({pos,a[pos],b[pos]});
		}
	}
	printf("%lld\n",ans);
}
}
int main(){
	ax_by_c::main();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8168kb

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'