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;
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 (stderr)
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 |
---|
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... |