Submission #366354

# Submission time Handle Problem Language Result Execution time Memory
366354 2021-02-14T04:56:09 Z CodePlatina Magenta (COCI21_magenta) C++14
30 / 110
87 ms 7276 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG

using namespace std;

vector<pii> gph[101010];
pii par[101010];

int dst(int x, int p, int y, int d)
{
    if(x == y) return d;
    for(auto [i, j] : gph[x]) if(i != p)
    {
        int t = dst(i, x, y, d + 1);
        if(t != -1) return t;
    }
    return -1;
}

void dfs(int x, int p)
{
    vector<pii> tmp;
    for(auto [y, i] : gph[x]) if(y != p)
    {
        tmp.push_back({y, i});
        par[y] = {x, i};
        dfs(y, x);
    }
    gph[x] = tmp;
}

bool sol(int x, int s)
{
    if(s == 1)
    {
        for(auto [y, i] : gph[x]) if(i) return true;
        return false;
    }

    for(auto [y, i] : gph[x])
    {
        if(i == 1) if(sol(y, 1)) return true;
        if(i == 2) if(sol(y, 0)) return true;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    int a, b; cin >> a >> b; --a; --b;

    for(int i = 1; i < n; ++i)
    {
        int x, y; cin >> x >> y; --x; --y;
        string st; cin >> st;
        int c;
        if(st == "plava") c = 0;
        else if(st == "crvena") c = 1;
        else c = 2;
        gph[x].push_back({y, c});
        gph[y].push_back({x, c});
    }

    int d = dst(a, -1, b, 0);

    int x = a, y = b;
    if(d & 1)
    {
        swap(x, y);
        for(int i = 0; i < n; ++i)
            for(auto &j : gph[i])
            if(j.ss < 2) j.ss = 1 - j.ss;
    }

    dfs(x, -1);

    int root = y;
    for(int i = 0; i < (d - 1) / 2; ++i)
    {
        if(!par[root].ss) break;
        root = par[root].ff;
    }

    if(sol(root, 0)) cout << "Magneta";
    else if(d & 1) cout << "Marin";
    else cout << "Paula";
}

Compilation message

Main.cpp: In function 'int dst(int, int, int, int)':
Main.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto [i, j] : gph[x]) if(i != p)
      |              ^
Main.cpp: In function 'void dfs(int, int)':
Main.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for(auto [y, i] : gph[x]) if(y != p)
      |              ^
Main.cpp: In function 'bool sol(int, int)':
Main.cpp:47:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |         for(auto [y, i] : gph[x]) if(i) return true;
      |                  ^
Main.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for(auto [y, i] : gph[x])
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Incorrect 2 ms 2668 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 7276 KB Output is correct
2 Correct 76 ms 7276 KB Output is correct
3 Correct 87 ms 7276 KB Output is correct
4 Correct 77 ms 7276 KB Output is correct
5 Correct 75 ms 7276 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Incorrect 2 ms 2668 KB Output isn't correct
4 Halted 0 ms 0 KB -