답안 #373006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373006 2021-03-03T01:56:40 Z sam571128 Magenta (COCI21_magenta) C++14
110 / 110
95 ms 11244 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5+5;
vector<pair<int,int>> adj[N]; //u -> {v,0/1/2} => 0->blue, 1->red, 2-> magenta
int dis[N][2], can[N][2], cnt = 0, ok = 0, hunter;
bool blue,red;
int a,b, len;

void dfs(int u, int c, int par){
	for(auto [v,cc] : adj[u]){
		if(v==par) continue;
		if(v==b) len = dis[u][c] + 1; 
		if(cc==(c^1)) continue;
		dis[v][c] = dis[u][c]+1;
		dfs(v,c,u);
	}
}

void dfs2(int u, int par){
	for(auto [v,cc] : adj[u]){
		if(v==par||cc==hunter||(dis[v][hunter]!=-1&&dis[v][hunter] <= dis[v][hunter^1])) continue;
		if(dis[u][hunter]==-1&&dis[v][hunter]==-1) ok = 1;
		dfs2(v,u);
	}
}

signed main(){
	fastio
	map<string,int> get;
	get["plava"] = 0;
	get["crvena"] = 1;
	get["magenta"] = 2;
	int n;
	cin >> n;
	cin >> a >> b;
	for(int i = 1;i < n;i++){
		int u,v; string s;
		cin >> u >> v >> s;
		adj[u].push_back({v,get[s]});
		adj[v].push_back({u,get[s]});
		if(get[s]!=1&&((u==a&&v!=b)||(u!=b&&v==a))) blue = 1;
		if(get[s]!=0&&(u==b||v==b)) red = 1;
	}
	if(!blue){
		cout << "Marin\n";
		return 0;
	}else if(!red){
		cout << "Paula\n";
		return 0;
	}
	fill(&dis[0][0],&dis[N-1][1],-1);
	dis[a][0] = 0;
	dfs(a,0,-1);
	dis[b][1] = 0;
	dfs(b,1,-1);
	if(len&1^1) hunter = 0; else hunter = 1;
	dfs2((hunter ? a : b),-1);
	if(!ok){
		cout << (hunter==0 ? "Paula" : "Marin") << "\n";
	}else{
		cout << "Magenta\n";
	}
}

Compilation message

Main.cpp: In function 'void dfs(long long int, long long int, long long int)':
Main.cpp:15:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |  for(auto [v,cc] : adj[u]){
      |           ^
Main.cpp: In function 'void dfs2(long long int, long long int)':
Main.cpp:25:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |  for(auto [v,cc] : adj[u]){
      |           ^
Main.cpp: In function 'int main()':
Main.cpp:61:8: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   61 |  if(len&1^1) hunter = 0; else hunter = 1;
      |     ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 4224 KB Output is correct
3 Correct 3 ms 4204 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 4204 KB Output is correct
6 Correct 3 ms 4204 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 3 ms 4204 KB Output is correct
11 Correct 3 ms 4204 KB Output is correct
12 Correct 3 ms 4204 KB Output is correct
13 Correct 3 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 9464 KB Output is correct
2 Correct 87 ms 9452 KB Output is correct
3 Correct 94 ms 9452 KB Output is correct
4 Correct 90 ms 9580 KB Output is correct
5 Correct 85 ms 9452 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 3 ms 4204 KB Output is correct
8 Correct 3 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 4224 KB Output is correct
3 Correct 3 ms 4204 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 4204 KB Output is correct
6 Correct 3 ms 4204 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 3 ms 4204 KB Output is correct
11 Correct 3 ms 4204 KB Output is correct
12 Correct 3 ms 4204 KB Output is correct
13 Correct 3 ms 4204 KB Output is correct
14 Correct 95 ms 9464 KB Output is correct
15 Correct 87 ms 9452 KB Output is correct
16 Correct 94 ms 9452 KB Output is correct
17 Correct 90 ms 9580 KB Output is correct
18 Correct 85 ms 9452 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 3 ms 4204 KB Output is correct
21 Correct 3 ms 4204 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 4204 KB Output is correct
24 Correct 3 ms 4204 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 3 ms 4204 KB Output is correct
27 Correct 3 ms 4204 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 2 ms 2668 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 63 ms 9708 KB Output is correct
32 Correct 67 ms 9708 KB Output is correct
33 Correct 64 ms 11244 KB Output is correct
34 Correct 68 ms 11244 KB Output is correct