#include <bits/stdc++.h>
using namespace std;
struct BipartiteMatcher {
vector<vector<int>> g;
vector<int> L, R;
vector<bool> vis;
BipartiteMatcher(int n, int m):
g(n), L(n, -1),
R(m, -1), vis(n) {}
void addEdge(int a, int b) {
g[a].push_back(b);
}
bool match(int x) {
if (vis[x]) return 0;
vis[x] = 1;
for (int v : g[x])
if (R[v] == -1)
return R[L[x] = v] = x, 1;
for (int v : g[x])
if (match(R[v]))
return R[L[x] = v] = x, 1;
return 0;
}
vector<int> solve() {
int cnt = 1;
while (cnt--) {
fill(vis.begin(), vis.end(), 0);
for (int i = 0; i < L.size(); ++i)
cnt |= L[i] == -1 and match(i);
}
vector<int> res(L.size());
for (int i = 0; i < L.size(); ++i) {
if (L[i] == -1) res[i] = 1;
else {
fill(vis.begin(), vis.end(), 0);
vis[i] = 1;
int v= L[i];
R[v] = -1; L[i] = -1;
cnt = 0;
for (int i = 0; i < L.size(); ++i) {
cnt |= L[i] == -1 and match(i);
}
if (cnt) {
res[i] = 1;
} else {
res[i] = 0;
R[L[i] = v] = i;
}
}
}
return res;
}
};
int main() {
int n, m;
cin >> n >> m;
BipartiteMatcher BM(n, n);
for (int i = 1; i <= m; ++i) {
int a, b;
cin >> a >> b;
BM.addEdge(a - 1, b - 1);
}
vector<int> res = BM.solve();
for (int v : res) {
cout << (v ? "Mirko" : "Slavko") << endl;
}
return 0;
}
Compilation message
planinarenje.cpp: In member function 'std::vector<int> BipartiteMatcher::solve()':
planinarenje.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); ++i)
~~^~~~~~~~~~
planinarenje.cpp:36:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); ++i) {
~~^~~~~~~~~~
planinarenje.cpp:44:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); ++i) {
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
9 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
712 KB |
Output is correct |
2 |
Correct |
321 ms |
748 KB |
Output is correct |
3 |
Correct |
268 ms |
764 KB |
Output is correct |
4 |
Correct |
340 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
376 KB |
Output is correct |
2 |
Correct |
11 ms |
376 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
376 KB |
Output is correct |
2 |
Correct |
26 ms |
440 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
508 KB |
Output is correct |
2 |
Correct |
152 ms |
760 KB |
Output is correct |
3 |
Correct |
69 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
504 KB |
Output is correct |
2 |
Correct |
112 ms |
628 KB |
Output is correct |
3 |
Correct |
71 ms |
508 KB |
Output is correct |
4 |
Correct |
12 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
632 KB |
Output is correct |
2 |
Correct |
82 ms |
504 KB |
Output is correct |
3 |
Correct |
95 ms |
632 KB |
Output is correct |
4 |
Correct |
26 ms |
504 KB |
Output is correct |