QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252076#6396. Puzzle: Kusabiucup-team1074WA 2ms13124kbC++203.8kb2023-11-15 15:27:342023-11-15 15:27:35

Judging History

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

  • [2023-11-15 15:27:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13124kb
  • [2023-11-15 15:27:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define list sajioaw
const LL maxn = 4e05+7;
const LL N=1e05+10;
const LL mod=1e09+7;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >t;
priority_queue<LL> q;
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
int n , m;
int a[N];
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0;
	}
}
struct Node{
	int fa;
	vector<int>ch;
	string str;
	int depth;
	int dai = 0;//携带的点
}tr[N];
//当一个点的所有儿子都被访问,那么该点将无法被访问
void dfs(){
	queue<Node>q;
	tr[1].depth = 1;
	tr[1].str = "-";
	q.push(tr[1]);
	while(!q.empty()){
		Node tmp = q.front();
		q.pop();
		for(auto it : tmp.ch){
			tr[it].depth = tmp.depth + 1;
			q.push(tr[it]);
		}
	}
}
int cmp(int a, int b){
	return tr[a].depth < tr[b].depth;
}
vector<int>id[N];
void solve() 
{
	cin >> n;
	for(int i = 2 ; i <= n ; i ++){
		int ch , fa;
		string s;
		cin >> ch >> fa >> s;
		tr[fa].ch.pb(ch);
		tr[ch].str = s;
		tr[ch].fa = fa;
	}
	dfs();
	int max_dep = 1;
	for(int i = 1 ; i <= n ; i ++){
		max_dep = max(max_dep , tr[i].depth); 
		id[tr[i].depth].pb(i);
	}
	vector< pair<int,int> >v;
	for(int i = max_dep - 1 ; i >= 1 ;i --){
		for(auto it : id[i]){
			//对it点进行操作
			vector<int>list[3];
			if(tr[it].str == "Tong"){
				list[0].pb(it);
			}
			if(tr[it].str == "Duan"){
				list[1].pb(it);			
			}
			if(tr[it].str == "Chang"){
				list[2].pb(it);				
			}
			for(auto x : tr[it].ch){
				if(tr[x].str == "Tong"){
					list[0].pb(x);
				}
				if(tr[tr[x].dai].str == "Tong"){
					list[0].pb(tr[x].dai);
				}
				if(tr[x].str == "Duan"){
					list[1].pb(x);
				}
				if(tr[tr[x].dai].str == "Duan"){
					list[1].pb(tr[x].dai);
				}
				if(tr[x].str == "Chang"){
					list[2].pb(x);
				}
				if(tr[tr[x].dai].str == "Chang"){
					list[2].pb(tr[x].dai);
				}
			}
			sort(list[0].begin() , list[0].begin() , cmp);
			sort(list[1].begin() , list[1].begin() , cmp);
			sort(list[2].begin() , list[2].begin() , cmp);
/*			printf("it : %d\n" , it);
			printf("list[0] : ");
			for(auto x :list[0]){
				cout<<x<<" ";
			}
			cout<<endl;
			printf("list[1] : ");
			for(auto x :list[1]){
				cout<<x<<" ";
			}
			cout<<endl;
			printf("list[2] : ");
			for(auto x :list[2]){
				cout<<x<<" ";
			}
			cout<<endl;*/
			int i = 0;
			int cnt = 0;
			int len = list[0].size();
			vector<int>res;//多于的下标
			for(int i = 1 ; i < len ; i ++){
				int x = list[0][i - 1] , y = list[0][i];
				if(tr[x].depth != tr[y].depth){
					res.pb(x);
					continue;
				}
				else{
					v.pb({x , y});
					i++;
				}
				if(i == len - 1){
					res.pb(list[0][len - 1]);
				}
			}
			int l = 0 , r = 0;
			int len1 = list[1].size() , len2 = list[2].size();
			for(; l < len1 || r < len2 ;){
				if(l < len1 && r < len2)
				{
					int x = list[1][l] , y = list[2][r];
					if(	tr[x].depth < tr[y].depth){
						v.pb({x , y});
						l ++;
						r ++;
					}
					else{
						res.pb(y);
						r++;						
					}
				}
				else if(l < len1){
					int x = list[1][l];
					res.pb(x);
					l++;
				}
				else if(r < len2){
					int y = list[2][r];
					res.pb(y);
					r++;
				}
			}
			if(res.size() > 1){
				cout<<"NO\n";
			}
			else if(res.size() == 1){
				if(res[0] != it)
					tr[it].dai = res[0];
			}
			else{
				tr[it].str = "-";
			}
		//	cout<<tr[it].dai<<endl;
		}
	}
	cout<<"YES\n";
	for(auto it : v){
		cout<<it.x<<" "<<it.y<<endl;
	}
}            
int main() 
{
    int t=1;
//	cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 13124kb

input:

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

output:

YES
6 8

result:

wrong output format Unexpected end of file - int32 expected