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>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
vector<vi> adj;
vi match;
bool augmentingPath(int l, int r) {
// l and r are the number of nodes on left and right side.
// It will be assumed that nodes 0 -> l-1 are the ones on the left side and rest l -> l+r-1 on the right
vi pre(l+r, -1);
int end = -1;
queue<int> q;
for_(i, 0, l) if (match[i] == -1) {
q.push(i);
pre[i] = i;
}
while (q.size() and end == -1) {
int p = q.front(); q.pop();
bool right = p >= l;
for (int i: adj[p]) if (pre[i] == -1 and match[i] != -2 and ((match[p] == i) == right)) {
assert((i < l) ^ (p < l));
pre[i] = p;
// found an unmatched edge on the right side
if (match[i] == -1) {
end = i;
break;
}
q.push(i);
}
}
if (end == -1) return false; // couln't find augmenting path
// update the matching to include the flipped edges in the augmenting path
int p = end;
while (true) {
if (pre[p] == p) break;
match[p] = pre[p];
match[pre[p]] = p;
p = pre[pre[p]];
}
return 1;
}
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
adj.resize(2*n); match.resize(2*n, -1);
for_(i, 0, m) {
int a, b; cin >> a >> b;
a -= 1; b += n-1;
adj[a].push_back(b);
adj[b].push_back(a);
}
int full = 0;
while (true) {
int v = augmentingPath(n, n);
if (!v) break;
full += v;
}
for_(i, 0, n) {
bool first = true;
if (match[i] == -1) first = false;
else {
vi prev = match;
match[match[i]] = -1;
match[i] = -2;
if (augmentingPath(n, n)) first = false;
match[i] = -1;
swap(match, prev);
}
cout << (first ? "Slavko" : "Mirko") << endl;
}
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... |