# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240274 | MrRobot_28 | Planinarenje (COCI18_planinarenje) | C++17 | 219 ms | 1148 KiB |
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;
vector <vector <int> > g;
vector <int> used, mat, mat1;
bool dfs(int v, int cnt)
{
if(used[v] == cnt)
{
return false;
}
used[v] = cnt;
for(int i = 0; i < g[v].size(); i++){
int to = g[v][i];
if(mat[to] == -1 || dfs(mat[to], cnt))
{
mat[to] = v;
return true;
}
}
return false;
}
bool dfs1(int v, int cnt)
{
if(used[v] == cnt)
{
return false;
}
used[v] = cnt;
for(int i = 0; i < g[v].size(); i++){
int to = g[v][i];
if(used[to] == cnt)
{
continue;
}
if(mat1[to] == -1 || dfs1(mat1[to], cnt))
{
mat1[to] = v;
return true;
}
}
return false;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
g.resize(2 * n);
mat1.resize(2 * n ,-1);
mat.resize(2 * n, -1);
used.resize(2 * n);
for(int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--;
b--;
b += n;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 0;i < n; i++)
{
dfs(i, i + 1);
}
int cnt1 = 0;
for(int i = n; i < n * 2; i++)
{
if(mat[i] != -1)
{
cnt1++;
}
}
vector <bool> ans(n);
for(int i = 0; i < n; i++)
{
int st = -1;
for(int j = 0; j < 2 * n; j++){
mat1[j] = -1;
}
for(int j = 0; j < 2 * n; j++)
{
if(mat[j] != -1 && mat[j] != i)
{
mat1[mat[j]] = j;
}
if(mat[j] == i)
{
st = j;
}
}
used[i] = n + i + 1;
if(st != -1)
{
dfs1(st, n + i + 1);
}
int cnt2 = 0;
for(int j = 0; j < n; j++)
{
if(mat1[j] != -1)
{
cnt2++;
}
}
if(cnt1 == cnt2)
{
ans[i] = true;
}
else
{
ans[i] = false;
}
}
for(int i = 0; i < n; i++)
{
if(ans[i])
{
cout << "Mirko\n";
}
else
{
cout << "Slavko\n";
}
}
return 0;
}
Compilation message (stderr)
# | 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... |