답안 #373002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373002 2021-03-03T01:20:44 Z sam571128 Magenta (COCI21_magenta) C++14
30 / 110
98 ms 11740 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], can[N][2], cnt = 0;

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

void check(int u, int c, int par){
	can[u][c] = 1;
	cnt++;
	for(auto [v,cc] : adj[u]){
		if(v==par) continue;
		if(cc==c||cc==2) check(v,c,u);
	}
}

vector<pair<int,int>> edges;
signed main(){
	fastio
	map<string,int> get;
	get["plava"] = 0;
	get["crvena"] = 1;
	get["magenta"] = 2;
	int n;
	cin >> n;
	int a,b;
	cin >> a >> b;
	bool onlyblue = 1;
	for(int i = 1;i < n;i++){
		int u,v; string s;
		cin >> u >> v >> s;
		if(s!="plava") onlyblue = 0;
		adj[u].push_back({v,get[s]});
		adj[v].push_back({u,get[s]});
		edges.push_back({u,v});
	}
	if(onlyblue) return cout << "Paula\n", 0;
	dfs(a,-1);
	check(a,0,-1);
	if(cnt==1) return cout << "Marin\n", 0;
	check(b,1,-1);
	bool ok = true;
	int hunter;
	if(dis[b]&1^1) hunter = 0; else hunter = 1;
	for(auto [u,v] : edges){
		if(can[u][hunter^1]&&can[v][hunter^1]&&!can[u][hunter]&&!can[v][hunter]){
			ok = false;
		}
	}
	if(ok){
		if(hunter==0) cout << "Paula\n";
		else cout << "Marin\n";
	}else{
		cout << "Magenta\n";
	}
}

Compilation message

Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:13:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   13 |  for(auto [v,c] : adj[u]){
      |           ^
Main.cpp: In function 'void check(long long int, long long int, long long int)':
Main.cpp:23:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |  for(auto [v,cc] : adj[u]){
      |           ^
Main.cpp: In function 'int main()':
Main.cpp:56:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   56 |  if(dis[b]&1^1) hunter = 0; else hunter = 1;
      |     ~~~~~~^~
Main.cpp:57:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   57 |  for(auto [u,v] : edges){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Incorrect 2 ms 2668 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 11740 KB Output is correct
2 Correct 98 ms 11740 KB Output is correct
3 Correct 94 ms 11740 KB Output is correct
4 Correct 94 ms 11740 KB Output is correct
5 Correct 91 ms 11740 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Incorrect 2 ms 2668 KB Output isn't correct
5 Halted 0 ms 0 KB -