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;
const int N = 5e3 + 12;
int n, m;
int par[N], vis[N], loc;
vector <int> ad[N];
string ans[2] = {"Slavko\n", "Mirko\n"};
void init();
void solve();
bool dfs(int);
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
init();
solve();
return 0;
}
void init() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
ad[v].push_back(u);
}
return;
}
void solve() {
for (int i = 0; i < N; i++) par[i] = -1;
for (int i = 0; i < n; i++) {
loc = i + 1;
dfs(i);
}
for (int i = 0; i < n; i++) {
int val = 0;
if (par[i] == -1) val = 1;
else {
loc = n + 1 + i;
vis[i] = loc;
if (dfs(par[i])) {
par[i] = -1;
val = 1;
}
}
cout << ans[val];
}
return;
}
bool dfs(int root) {
for (auto x : ad[root]) {
if (vis[x] == loc) continue;
vis[x] = loc;
if (par[x] == -1) {
par[x] = root;
return 1;
}
if (dfs(par[x])) {
par[x] = root;
return 1;
}
}
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... |