Submission #978637

#TimeUsernameProblemLanguageResultExecution timeMemory
978637bebraPlaninarenje (COCI18_planinarenje)C++17
96 / 160
3 ms860 KiB
#include <bits/stdc++.h> #include <random> using namespace std; #define dbg(x) cerr << #x << ": " << x << endl; const int MAX_N = 5000 + 5; vector<int> g[MAX_N]; vector<int> g2[MAX_N]; int used[MAX_N]; int match[MAX_N]; int left_match[MAX_N]; int timer = 1; bool try_kuhn(int v) { if (used[v] == timer) { return false; } used[v] = timer; for (auto u : g[v]) { if (match[u] == -1) { match[u] = v; left_match[v] = u; return true; } } for (auto u : g[v]) { if (try_kuhn(match[u])) { match[u] = v; left_match[v] = u; return true; } } return false; } bool can[MAX_N]; void dfs(int v) { if (used[v] == timer) { return; } used[v] = timer; if (left_match[v] == -1) { can[v] = true; return; } for (auto u : g2[left_match[v]]) { if (u == v) continue; dfs(u); can[v] = can[v] | can[u]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g2[v].push_back(u); } memset(match, -1, sizeof(match)); memset(left_match, -1, sizeof(left_match)); int cnt = 0; for (int v = 0; v < n; ++v) { if (try_kuhn(v)) { ++timer; ++cnt; } } ++timer; for (int v = 0; v < n; ++v) { if (used[v] != timer) { dfs(v); } if (can[v]) { cout << "Mirko\n"; } else { cout << "Slavko\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...