QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788234#7588. Monster HunterEdward2019WA 347ms48532kbC++231.5kb2024-11-27 16:19:012024-11-27 16:19:02

Judging History

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

  • [2024-11-27 16:19:02]
  • 评测
  • 测评结果:WA
  • 用时:347ms
  • 内存:48532kb
  • [2024-11-27 16:19:01]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int n,h[N],e[N],ne[N],idx;
inline void add(int a,int b){e[idx]=b,ne[idx]=h[a],h[a]=idx++;}
struct node{
	int a,b;
	inline bool operator < (const node t)const{
		if((a<b)>(t.a<t.b))return 0; 
		if((a<b)<(t.a<t.b))return 1;
		if(a<b)return (a>t.a);
		else return (b<t.b);
	}
	inline node operator + (const node y)const{
		int A=max(this->a,this->a-this->b+y.a);
		int B=this->b-this->a+y.b-y.a+A;
		return (node){A,B};
	}
}a[N];
priority_queue<pair<node,int>>q;
priority_queue<pair<node,int>>v[N];
inline void eval(int u){
	while(v[u].size()){
		if(v[u].top().first<a[u])return;
		int j=v[u].top().second;
		a[u]=a[u]+v[u].top().first,v[u].pop();
		if(v[u].size()<v[j].size())swap(v[u],v[j]);
		while(v[j].size())v[u].push(v[j].top()),v[j].pop();
	}
}
void dfs(int u,int fa){
	for(int i=h[u];~i;i=ne[i]){
		int j=e[i];
		if(j==fa)continue;
		dfs(j,u),v[u].emplace(a[j],j);
	}
	eval(u);
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		cin>>n,idx=0;
		for(int i=0;i<=n;i++)h[i]=-1,a[i].a=a[i].b=0;
		for(int i=2;i<=n;i++)cin>>a[i].a>>a[i].b;
		for(int i=1;i<n;i++){
			int a,b;
			cin>>a>>b;
			add(a,b),add(b,a);
		}
		dfs(1,-1);
		q.emplace(a[1],1);
		while(q.size()){
			auto t=q.top();q.pop();
			a[0]=a[0]+t.first;
			while(v[t.second].size())q.push(v[t.second].top()),v[t.second].pop();
		}
		cout<<a[0].a;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 17092kb

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: 347ms
memory: 48532kb

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:

634954985411567491916172411770905593836098912723199339419064806867371949966148458489084657366

result:

wrong output format Expected integer, but "634954985411567491916172411770...6867371949966148458489084657366" found