Submission #978617

# Submission time Handle Problem Language Result Execution time Memory
978617 2024-05-09T11:33:49 Z bebra Planinarenje (COCI18_planinarenje) C++17
144 / 160
1000 ms 856 KB
#include <bits/stdc++.h>
#include <random>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;


const int MAX_N = 5000 + 5;
vector<int> g[MAX_N];
int used[MAX_N];
int match[MAX_N];
int timer = 1;
bool covered[MAX_N];

bool dfs(int v) {
    if (used[v] == timer) {
        return false;
    }

    used[v] = timer;

    for (auto u : g[v]) {
        if (match[u] == -1) {
            match[u] = v;
            return true;
        }
    }

    for (auto u : g[v]) {
        if (dfs(match[u])) {
            match[u] = v;
            return true;
        }
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        g[u].push_back(v);
    }


    mt19937 rng(random_device{}());
    for (int v = 0; v < n; ++v) {
        shuffle(g[v].begin(), g[v].end(), rng);
    }

    memset(match, -1, sizeof(match));

    int cnt = 0;
    for (int v = 0; v < n; ++v) {
        if (dfs(v)) {
            ++timer;
            ++cnt;
            covered[v] = true;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!covered[i]) {
            cout << "Mirko\n";
            continue;
        }

        int curr = 0;
        memset(match, -1, sizeof(match));
        ++timer;
        for (int v = 0; v < n; ++v) {
            if (v == i) continue;

            if (dfs(v)) {
                ++timer;
                ++curr;
            }
        }

        if (curr < cnt) {
            cout << "Slavko\n";
        } else {
            cout << "Mirko\n";
        }
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 756 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 604 KB Output is correct
2 Correct 168 ms 600 KB Output is correct
3 Correct 133 ms 600 KB Output is correct
4 Correct 171 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 600 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 21 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 155 ms 604 KB Output is correct
3 Correct 54 ms 856 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1029 ms 668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 420 ms 848 KB Output is correct
2 Correct 98 ms 604 KB Output is correct
3 Correct 32 ms 600 KB Output is correct
4 Correct 43 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 604 KB Output is correct
2 Correct 35 ms 604 KB Output is correct
3 Correct 95 ms 700 KB Output is correct
4 Correct 281 ms 676 KB Output is correct