QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470729#6396. Puzzle: KusabiUESTC_xxx#WA 1ms7764kbC++201.7kb2024-07-10 16:05:472024-07-10 16:05:48

Judging History

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

  • [2024-07-10 16:05:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7764kb
  • [2024-07-10 16:05:47]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#define ll long long
#define lowbit(x) x&(-x)
using namespace std;
int n,s[500005],cy[500005],cx[500005],tot,c1,c2,c3;
vector<int>e[500005];
struct node{
	int d,tp,id;
}p[500005],a[500005];
bool cmp(node a,node b){
	if(a.d==b.d) return a.tp<b.tp;
	return a.d<b.d;
}
void dfs(int u,int dp){
	p[u].id=u;
	p[u].d=dp;
	s[u]=(p[u].tp!=0);
	for(int i=0;i<e[u].size();++i){
		int v=e[u][i];
		dfs(v,dp+1);
		s[u]+=s[v];
	}
	int cnt=0;
	if(p[u].tp) cnt++,a[cnt]=p[u];
	for(int i=0;i<e[u].size();++i){
		int v=e[u][i];
		if(s[v]%2) cnt++,a[cnt]=p[v];
	}
	sort(a+1,a+cnt+1,cmp);
	int f=0;
	for(int i=1;i<=cnt;++i){
		if(a[i].tp==1){
			if(a[i+1].tp==1&&a[i+1].d==a[i].d&&i!=cnt){
				tot++,cx[tot]=a[i].id,cy[tot]=a[i+1].id;
				i++;
			}
			else f++,p[u]=a[i];
		}
	}
	queue<node>q;
	for(int i=1;i<=cnt;++i){
		if(a[i].tp==1) continue;
		if(a[i].tp==3){
			q.push(a[i]);
		}
		if(a[i].tp==2){
			if(!q.size()) f++,p[u]=a[i];
			else{
				node g=q.front();
				tot++,cx[tot]=g.id,cy[tot]=a[i].id;
				q.pop();
			}
		}
	}
	while(q.size()){
		f++,p[u]=q.front();
		q.pop();
	}
	if(f>1) printf("NO"),exit(0);
	if(u==1&&f) printf("NO"),exit(0);
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;++i){
		int x,y;
		char s[8];
		scanf("%d%d%s",&x,&y,s);
		e[y].push_back(x);
		if(s[0]=='T') p[x].tp=1,c1++;
		if(s[0]=='C') p[x].tp=2,c2++;
		if(s[0]=='D') p[x].tp=3,c3++;
	}
	if(c1%2||(c1+c2)%2||c1!=c2) printf("NO"),exit(0);
	dfs(1,1);
	printf("YES\n");
	for(int i=1;i<=tot;++i){
		printf("%d %d\n",cx[i],cy[i]);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
2 1 -
3 1 -
4 2 Tong
5 2 Tong
6 3 Duan
7 3 -
8 7 Chang

output:

NO

result:

wrong answer Jury has answer but participant has not.