QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528423#6396. Puzzle: Kusabihnust_xiaoqi#WA 1ms9672kbC++201.6kb2024-08-23 13:55:052024-08-23 13:55:05

Judging History

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

  • [2024-08-23 13:55:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9672kb
  • [2024-08-23 13:55:05]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl "\n"

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;
pair<LL,LL> duan[N],chang[N],tong[N];
LL h[N];
LL n;
LL inde_duan,inde_chang,inde_tong;
bool check(){
	if(inde_chang!=inde_duan||(inde_tong&1)) return false;
	for(LL i=1;i<=inde_tong;i+=2){
		if(tong[i].second!=tong[i+1].second){
			return false;
		}
	}
	for(LL i=1;i<=inde_duan;++i){
		if(duan[i].second>=chang[i].second){
			return false;
		}
	}
	return true;
}
void solve() {
	cin >> n;
	if(n==1){
		cout<<"YES"<<endl;
		return;
	}
	for(int i = 1; i < n; i++) {
		LL data,data2;
		string str;
		cin>>data>>data2>>str;
		h[data]=h[data2]+1;
		if(str[0]=='T'){
			tong[++inde_tong]={data,h[data]};
		}else if(str[0]=='C'){
			chang[++inde_chang]={data,h[data]};
		}else if(str[0]=='D'){
			duan[++inde_duan]={data,h[data]};
		}
	}
	sort(tong+1,tong+inde_tong,[&](const auto& a,const auto &b){
		return a.second<b.second;
	});
	sort(duan+1,duan+inde_duan,[&](const auto& a,const auto &b){
		return a.second<b.second;
	});
	sort(chang+1,chang+inde_chang,[&](const auto& a,const auto &b){
		return a.second<b.second;
	});
	if(check()){
		cout<<"YES"<<endl;
		for(LL i=1;i<=inde_tong;i+=2){
			cout<<tong[i].first<<' '<<tong[i+1].first<<endl;
		}
		for(LL i=1;i<=inde_duan;++i){
			cout<<duan[i].first<<' '<<chang[i].first<<endl;
		}
	}else{
		cout<<"NO"<<endl;
	}
}

signed main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0);
	
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9672kb

input:

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

output:

YES
4 5
6 8

result:

ok Correct.

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 7884kb

input:

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

output:

YES
8 9
2 6
3 5
7 10

result:

wrong answer Edge 3-2 used twice.