This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
++timer;
dfs(v);
if (can[v]) {
cout << "Mirko\n";
} else {
cout << "Slavko\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |