#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 |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
604 KB |
Output is correct |
2 |
Correct |
16 ms |
860 KB |
Output is correct |
3 |
Correct |
6 ms |
812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
11 ms |
604 KB |
Output is correct |
3 |
Correct |
6 ms |
604 KB |
Output is correct |
4 |
Correct |
12 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
876 KB |
Output is correct |
4 |
Correct |
30 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
39 ms |
884 KB |
Output is correct |