Submission #1045356

#TimeUsernameProblemLanguageResultExecution timeMemory
1045356MorePipisekMagenta (COCI21_magenta)C++14
30 / 110
81 ms8796 KiB
#include <iostream> #include <vector> using namespace std; int n, a, b; vector<int> dist; vector<vector<pair<int, int>>> g; bool pih; void dfs(int v, int d = 0, int p = -1) { if (v == b) { pih = d % 2 == 0; return; } for (auto [u, c] : g[v]) { if (u != p) { dfs(u, d + 1, v); } } } void visit(int v, int d = 0, int p = -1) { dist[v] = d; for (auto [u, c] : g[v]) { if (c != pih && u != p) { visit(u, d + 1, v); } } } bool safe = false; void esc(int v, int d = 0, int p = -1) { for (auto [u, c] : g[v]) { if (u == p) { continue; } if (pih && dist[v] <= d) { continue; } if (!pih && dist[v] < d) { continue; } if (dist[v] == 1e9 && dist[u] == 1e9) { safe = true; } esc(u, d + 1, v); } } int main() { cin >> n >> a >> b; --a; --b; g.assign(n, {}); for (int i = 0; i < n - 1; ++i) { int u, v, c; cin >> u >> v; --u; --v; string col; cin >> col; if (col == "plava") { c = 0; } else if (col == "crvena") { c = 1; } else { c = 2; } g[u].emplace_back(v, c); g[v].emplace_back(u, c); } bool lp = true, lm = true; for (auto [u, c] : g[a]) { lp &= c == 1; } for (auto [u, c] : g[b]) { lm &= c == 0; } if (lp) { cout << "Marin" << endl; return 0; } else if (lm) { cout << "Paula" << endl; return 0; } dfs(a); dist.assign(n, 1e9); if (pih) { visit(a); esc(b); } else { visit(b); esc(a); } if (safe) { cout << "Magenta" << endl; } else if (pih) { cout << "Paula" << endl; } else { cout << "Marin" << endl; } }

Compilation message (stderr)

Main.cpp: In function 'void dfs(int, int, int)':
Main.cpp:15:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for (auto [u, c] : g[v]) {
      |               ^
Main.cpp: In function 'void visit(int, int, int)':
Main.cpp:24:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |     for (auto [u, c] : g[v]) {
      |               ^
Main.cpp: In function 'void esc(int, int, int)':
Main.cpp:33:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |     for (auto [u, c] : g[v]) {
      |               ^
Main.cpp: In function 'int main()':
Main.cpp:69:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     for (auto [u, c] : g[a]) {
      |               ^
Main.cpp:72:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |     for (auto [u, c] : g[b]) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...