//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <iostream>
#include <fstream>
using namespace std;
const int N = 10000 + 5;
int n, m;
vector<int> adj[N];
bool mark[N];
int match_up[N];
int match_down[N];
bool dfs(int v, int p = -1)
{
if (v == p)
{
return false;
}
mark[v] = true;
for (auto u : adj[v])
{
if (u == p)
{
continue;
}
if (match_up[u] == -1 || (!mark[match_up[u]] && dfs(match_up[u]))) { // augmenting path found!
match_up[u] = v;
match_down[v] = u;
return true;
}
}
return false;
}
int solver(int p = -1)
{
int ans = 0;
memset(match_down, -1, sizeof match_down);
memset(match_up, -1, sizeof match_up);
while (true)
{
bool finished = true;
memset(mark, 0, sizeof mark);
for (int i = 0; i < n * 2; i++)
{
if (match_down[i] == -1 && !mark[i] && dfs(i, p))
{
finished = false;
ans++;
}
}
if (finished)
{
break;
}
}
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
u--;
v--;
adj[2 * u].push_back(2 * v + 1);
adj[2 * v + 1].push_back(2 * u);
}
int max_matching = solver();
for (int i = 0; i < 2 * n; i += 2)
{
int u = match_down[i];
if (u == -1)
{
cout << "Mirko" << endl;
continue;
}
bool ok = true;
for (auto v: adj[u])
{
if (match_down[v] == -1)
{
ok = false;
}
}
if (ok)
{
cout << "Slavko" << endl;
}
else
{
cout << "Mirko" << endl;
}
}
}
Compilation message
planinarenje.cpp: In function 'int main()':
planinarenje.cpp:97:6: warning: unused variable 'max_matching' [-Wunused-variable]
int max_matching = solver();
^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
896 KB |
Output is correct |
2 |
Correct |
17 ms |
896 KB |
Output is correct |
3 |
Correct |
16 ms |
896 KB |
Output is correct |
4 |
Correct |
16 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
7 ms |
768 KB |
Output is correct |
3 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |