답안 #366333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366333 2021-02-14T03:11:26 Z kshitij_sodani Magenta (COCI21_magenta) C++14
110 / 110
175 ms 18028 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'

int n;
vector<int> adj[100001];
vector<int> adj2[100001];
vector<int> adj3[100001];

int dist[100001];
int dist2[100001];

int cc,dd;
int st=0;
//llo pp=0;
void dfs(int no,int par=-1,int levv=0){
	if(no==dd){
/*		if(levv==1){
			pp=1;
		}*/
		if(levv%2==0){
			//cout<<"Paula"<<endl;
		}
		else{
			st=1;
			//cout<<"Marin"<<endl;
		}
	}
	for(auto j:adj[no]){
		if(j!=par){
			dfs(j,no,levv+1);
		}
	}
}
void dfs2(int no,int par=-1,int levv=0){
	dist[no]=levv;
	for(auto j:adj2[no]){
		if(j!=par){
			dfs2(j,no,levv+1);
		}
	}
}
void dfs3(int no,int par=-1,int levv=0){
	dist2[no]=levv;
	for(auto j:adj3[no]){
		if(j!=par){
			dfs3(j,no,levv+1);
		}
	}
}
int ans=1;
void dfs4(int no,int par=-1,int levv=0){
	for(auto j:adj2[no]){
		if(j!=par){
			if(dist2[no]==-1 and dist2[j]==-1){
				ans=0;
			}
			if(dist2[j]==-1 or dist2[j]>=dist[j]){
				dfs4(j,no,levv+1);
			}
		}
	}
}

void dfs5(int no,int par=-1,int levv=0){
	for(auto j:adj3[no]){
		if(j!=par){
			if(dist[no]==-1 and dist[j]==-1){
				ans=0;
			}
			if(dist[j]==-1 or dist[j]>dist2[j]){
				dfs5(j,no,levv+1);
			}
		}
	}
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	
	cin>>cc>>dd;
	cc--;
	dd--;
	for(int i=0;i<n-1;i++){
		int aa,bb;
		cin>>aa>>bb;
		string ee;
		cin>>ee;
		aa--;
		bb--;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
		if(ee=="plava" or ee=="magenta"){
			adj2[aa].pb(bb);
			adj2[bb].pb(aa);
		}
		if(ee=="crvena" or ee=="magenta"){
			adj3[aa].pb(bb);
			adj3[bb].pb(aa);
		}
	}
	if(true){
		if(adj2[cc].size()==0){
			cout<<"Marin"<<endl;
			return 0;
		}
		if(adj2[cc].size()==1){
			if(adj2[cc][0]==dd){
				cout<<"Marin"<<endl;
				return 0;
			}
		}
	}
	if(true){
		if(adj3[dd].size()==0){
			cout<<"Paula"<<endl;
			return 0;
		}
	}



	dfs(cc);
	for(int i=0;i<n;i++){
		dist[i]=-1;
		dist2[i]=-1;
	}
	dfs2(cc);
	dfs3(dd);
/*	for(int i=0;i<n;i++){
		cout<<dist[i]<<":"<<dist2[i]<<endl;
	}*/
	if(st==0){
		dfs5(dd);
		if(ans==0){
			cout<<"Magenta"<<endl;
		}
		else{
			cout<<"Paula"<<endl;
		}
	}
	else{
		dfs4(cc);
		if(ans==0){
			cout<<"Magenta"<<endl;
		}
		else{
			cout<<"Marin"<<endl;
		}
	}








 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 18028 KB Output is correct
2 Correct 161 ms 17900 KB Output is correct
3 Correct 164 ms 17932 KB Output is correct
4 Correct 161 ms 18028 KB Output is correct
5 Correct 153 ms 17900 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 175 ms 18028 KB Output is correct
15 Correct 161 ms 17900 KB Output is correct
16 Correct 164 ms 17932 KB Output is correct
17 Correct 161 ms 18028 KB Output is correct
18 Correct 153 ms 17900 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 5 ms 7404 KB Output is correct
26 Correct 5 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 5 ms 7404 KB Output is correct
30 Correct 5 ms 7532 KB Output is correct
31 Correct 113 ms 15724 KB Output is correct
32 Correct 111 ms 15724 KB Output is correct
33 Correct 124 ms 16492 KB Output is correct
34 Correct 125 ms 16492 KB Output is correct