답안 #400046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400046 2021-05-07T08:48:54 Z jenkinsser Magenta (COCI21_magenta) C++17
30 / 110
83 ms 11360 KB
#include <bits/stdc++.h>
#define FOR(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define for0(ii,bb) FOR(ii,0,bb)
#define for1(ii,bb) FOR(ii,1,bb+1)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define pdi pair<double,int>
#define vi vector<int>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll

using namespace std;

const int N = 1e5+5;
const int INF = 1e9+5;
const int mod = 998244353;

int n,s[2],can_move[2],dist[N][2],len,kacan;
vector<pii> g[N];

string str[3]={"Paula","Marin","Magenta"};
map<string,int> col;

void dfs(int v,int p,int x){
    for(auto e:g[v]){
        if(e.st==p)continue;
        if(e.st==s[x^1])
            len=dist[v][x]+1;
        if(e.nd!=(x^1)){
            dist[e.st][x]=dist[v][x]+1;
            dfs(e.st,v,x);
        }
    }
}

bool check(int v,int p=-1){
    bool ok=false;
    for(auto e:g[v]){
        if(e.st==p||e.nd==(kacan^1)||(dist[e.st][kacan^1]!=-1&&dist[e.st][kacan]>=dist[e.st][kacan^1]))
            continue;
        if(dist[e.st][kacan^1]==-1)
            return true;
        ok|=check(e.st,v);
    }
    return ok;
}

void print(int x){
    cout << str[x] << nl;
    exit(0);
}

signed main(){
    fastio()
    col["plava"]=0;
    col["crvena"]=1;
    col["magenta"]=2;
    cin >> n >> s[0] >> s[1];
    for(int i=1;i<n;i++){
        int u,v;
        string t;
        cin >> u >> v >> t;
        int c=col[t];
        g[u].pb({v,c});
        g[v].pb({u,c});
        if(c!=1&&((s[0]==u&&s[1]!=v)||(s[0]==v&&s[1]!=u)))
            can_move[0]=1;
        if(c!=0&&(s[1]==u||s[1]==v))
            can_move[1]=1;
    }
    if(!can_move[0])
        print(1);
    if(!can_move[1])
        print(0);
    memset(dist,-1,sizeof(dist));
    dist[s[0]][0]=0;
    dfs(s[0],-1,0);
    dist[s[1]][1]=0;
    dfs(s[1],-1,1);
    kacan=(len+1)%2;
    if(check(s[kacan]))
        print(2);
    print(kacan^1);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Incorrect 3 ms 4172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 11360 KB Output is correct
2 Correct 73 ms 11220 KB Output is correct
3 Correct 80 ms 11148 KB Output is correct
4 Correct 69 ms 11144 KB Output is correct
5 Correct 70 ms 11148 KB Output is correct
6 Correct 2 ms 2676 KB Output is correct
7 Correct 3 ms 4172 KB Output is correct
8 Correct 4 ms 4208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Incorrect 3 ms 4172 KB Output isn't correct
3 Halted 0 ms 0 KB -