/*
بسم الله الرحمن الرحیم
(; طلا یک جهانی
*/
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000 + 5;
int n, m, mch[MAX_N];
bool mark[MAX_N], mch_mark[MAX_N];
vector<int> adj[MAX_N];
void read_input() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
}
}
bool dfs(int v) {
mark[v] = true;
for (int u: adj[v])
if (!~mch[u] || !mark[mch[u]] && dfs(mch[u])) {
mch[u] = v;
mch_mark[v] = true;
return true;
}
return false;
}
void solve() {
memset(mch, -1, sizeof mch);
for (bool check = true; check; memset(mark, 0, sizeof mark)) {
check = false;
for (int i = 0; i < n; i++)
if (!mark[i] && !mch_mark[i])
check |= dfs(i);
}
for (int i = 0; i < n; i++)
if (!mch_mark[i])
dfs(i);
}
void print_output() {
for (int i = 0; i < n; i++)
if (mark[i])
cout << "Mirko\n";
else
cout << "Slavko\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
read_input();
solve();
print_output();
}
Compilation message
planinarenje.cpp: In function 'bool dfs(int)':
planinarenje.cpp:28:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if (!~mch[u] || !mark[mch[u]] && dfs(mch[u])) {
~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |