Submission #684669

# Submission time Handle Problem Language Result Execution time Memory
684669 2023-01-22T09:51:09 Z LeonaRaging Planinarenje (COCI18_planinarenje) C++14
160 / 160
6 ms 596 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const int maxn = 5e3 + 4;

int n, m, t, mt[maxn], vis[maxn];
bool good[maxn], used[maxn];
vector<int> adj[maxn];

bool try_kuhn(int u) {
    if (vis[u] != t) vis[u] = t;
    else return 0;
    for (int v : adj[u])
        if (!mt[v] || try_kuhn(mt[v])) {
            mt[v] = u;
            return 1;
        }
    return 0;
}

void dfs(int u) {
    if (vis[u]) return;
    vis[u] = 1;
    for (int v : adj[u])
        if (mt[v]) {
            good[mt[v]] = 0;
            dfs(mt[v]);
        }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1, u, v; i <= m; i++) {
        cin >> u >> v;
        adj[u].pb(v);
    }
    for (int u = 1; u <= n; u++)
        for (int v : adj[u])
            if (!mt[v]) {
                mt[v] = u;
                used[u] = 1;
                break;
            }
    for (int u = 1; u <= n; u++)
        if (!used[u])
            t++, try_kuhn(u);
    for (int u = 1; u <= n; u++)
            good[mt[u]] = 1;
    memset(vis, 0, sizeof vis);
    for (int u = 1; u <= n; u++)
        if (!good[u])
            t++, dfs(u);
    for (int u = 1; u <= n; u++)
        cout << (good[u] ? "Slavko" : "Mirko") << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 552 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 3 ms 516 KB Output is correct