#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 10;
int n, m, k, pair_[MAXN << 1];
vector<int> adj[MAXN << 1];
bool mark[MAXN << 1], match[MAXN << 1];
bool answer[MAXN << 1];
bool dfs(int v) {
mark[v] = true;
for (auto i : adj[v])
if (!match[i] || (!mark[pair_[i]] && dfs(pair_[i]))) {
match[v] = match[i] = true;
pair_[v] = i;
pair_[i] = v;
return true;
}
return false;
}
void dfs_(int v) {
mark[v] = true;
for (auto i : adj[v]) {
if (match[i] && !mark[pair_[i]]) {
answer[pair_[i]] = false;
dfs_(pair_[i]);
}
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
cin >> n >> k; m = n;
for (int i = 0; i < k; i++) {
int u, v; cin >> u >> v; v += n;
adj[u].push_back(v); adj[v].push_back(u);
}
while (true) {
bool lf = false;
memset(mark, 0, sizeof(mark));
for (int i = 1; i <= n; i++)
if (!match[i] && dfs(i)) {
lf = true;
}
if (!lf)
break;
}
memset(mark, 0, sizeof(mark));
for (int i = 1; i <= n + m; i++)
if (match[i])
answer[i] = true;
for (int i = 1; i <= n + m; i++) {
if (match[i] || mark[i])
continue;
dfs_(i);
}
for (int i = 1; i <= n; i++) {
if (answer[i])
cout << "Slavko" << '\n';
else
cout << "Mirko" << '\n';
}
//cin >> n;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
924 KB |
Output is correct |
2 |
Correct |
2 ms |
984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
984 KB |
Output is correct |
2 |
Correct |
2 ms |
1008 KB |
Output is correct |
3 |
Correct |
2 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1072 KB |
Output is correct |
2 |
Correct |
2 ms |
1080 KB |
Output is correct |
3 |
Correct |
2 ms |
1084 KB |
Output is correct |
4 |
Correct |
3 ms |
1164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1428 KB |
Output is correct |
2 |
Correct |
5 ms |
1608 KB |
Output is correct |
3 |
Correct |
5 ms |
1676 KB |
Output is correct |
4 |
Correct |
4 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Correct |
3 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
4 ms |
1740 KB |
Output is correct |
3 |
Correct |
3 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1740 KB |
Output is correct |
2 |
Correct |
5 ms |
1740 KB |
Output is correct |
3 |
Correct |
4 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1740 KB |
Output is correct |
2 |
Correct |
5 ms |
1740 KB |
Output is correct |
3 |
Correct |
3 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Correct |
4 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1740 KB |
Output is correct |