Submission #239662

# Submission time Handle Problem Language Result Execution time Memory
239662 2020-06-17T06:37:31 Z kartel Planinarenje (COCI18_planinarenje) C++14
160 / 160
34 ms 3180 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define pii pair <int, int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

int mk[N], mrk[N], i, x, y, n, m;
vector <int> g[N];

int try_kuhn(int v)
{
    if (mrk[v]) return 0;

    mrk[v] = 1;

    for (auto u : g[v])
        if (mk[u] == -1 || try_kuhn(mk[u]))
        {
            mk[u] = v;
            return 1;
        }

    return 0;
}

int dfs(int v)
{
    if (mrk[v]) return 0;

    mrk[v] = 1;

    for (auto u : g[v])
        if (mk[u] == -1 || dfs(mk[u]))
            return 1;

    return 0;
}

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n >> m;
    for (i = 1; i <= m; i++)
    {
        cin >> x >> y;

        y += n;

        g[x].pb(y);
        g[y].pb(x);
    }

    for (i = 1; i <= n * 2; i++) mk[i] = -1;

    for (i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n * 2; j++) mrk[j] = 0;

        try_kuhn(i);
    }

    for (i = n + 1; i <= n + n; i++)
        if (mk[i] != -1)
            mk[mk[i]] = i;

    for (i = 1; i <= n; i++)
        if (mk[i] == -1)
          cout << "Mirko" << el;
    else
    {
        for (int j = 1; j <= n * 2; j++) mrk[j] = 0;

        bool can = dfs(mk[i]);

        cout << ((!can) ? "Slavko" : "Mirko") << el;
    }
}

/*
8 8
...).).*
*....)..
.)*(..).
(*)((...
.)).)(..
.)(.)..(
...).(.*
M.......
*/
//
//110000
//1100
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3072 KB Output is correct
2 Correct 18 ms 3180 KB Output is correct
3 Correct 17 ms 3072 KB Output is correct
4 Correct 19 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2816 KB Output is correct
2 Correct 19 ms 2944 KB Output is correct
3 Correct 15 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2816 KB Output is correct
2 Correct 8 ms 2816 KB Output is correct
3 Correct 14 ms 2816 KB Output is correct
4 Correct 15 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2944 KB Output is correct
2 Correct 18 ms 3072 KB Output is correct
3 Correct 11 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2944 KB Output is correct
2 Correct 13 ms 3072 KB Output is correct
3 Correct 9 ms 2944 KB Output is correct
4 Correct 34 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3072 KB Output is correct
2 Correct 9 ms 2944 KB Output is correct
3 Correct 13 ms 3072 KB Output is correct
4 Correct 27 ms 2936 KB Output is correct