#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#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;
}
Compilation message
planinarenje.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
planinarenje.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
1016 KB |
Output is correct |
2 |
Correct |
458 ms |
1152 KB |
Output is correct |
3 |
Correct |
392 ms |
1016 KB |
Output is correct |
4 |
Correct |
468 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
384 KB |
Output is correct |
2 |
Correct |
18 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
496 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
512 KB |
Output is correct |
2 |
Correct |
330 ms |
1184 KB |
Output is correct |
3 |
Correct |
131 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
640 KB |
Output is correct |
2 |
Correct |
212 ms |
888 KB |
Output is correct |
3 |
Correct |
65 ms |
640 KB |
Output is correct |
4 |
Correct |
11 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
760 KB |
Output is correct |
2 |
Correct |
75 ms |
640 KB |
Output is correct |
3 |
Correct |
200 ms |
888 KB |
Output is correct |
4 |
Correct |
40 ms |
640 KB |
Output is correct |