Submission #494785

# Submission time Handle Problem Language Result Execution time Memory
494785 2021-12-16T11:23:38 Z abc864197532 Parachute rings (IOI12_rings) C++17
100 / 100
2015 ms 119460 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define X first
#define Y second
#define pii pair<int, int>
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
    cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
    for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args);
#include "grader_B.cpp"
#else
#define test(args...) void(0);
#endif
const int N = 1000000;

vector <pii> edge;
vector <int> adj[N];
int deg[N], n, mx, id[N];
bool grt, dead[4];

struct Dsu {
    int dsu[N], sz[N];
    bool cyc;
    
    void init(int n) {
        iota(dsu, dsu + n, 0);
        fill(sz, sz + n, 1);
        cyc = false;
    }

    int Find(int x) {
        if (dsu[x] == x)
            return x;
        return dsu[x] = Find(dsu[x]);
    }
    bool Union(int u, int v) {
        u = Find(u), v = Find(v);
        if (u == v)
            return cyc = true;
        dsu[u] = v;
        sz[v] += sz[u];
        return false;
    }
} ord, p[4];

void Init(int N) {
    n = mx = N;
    ord.init(n);
    for (int i : {0, 1, 2, 3})
        p[i].init(n);
}

void gen(int v) {
    assert(deg[v] == 3);
    id[0] = v;
    for (int i : {1, 2, 3})
        id[i] = adj[v][i - 1];
    for (int i = 0; i < 4; ++i) {
        int v = id[i];
        for (pii A : edge) {
            if (A.X != v && A.Y != v) {
                p[i].Union(A.X, A.Y);
            }
        }
    }
}

void upd(int v) {
    if (deg[v] == 3) {
        for (int i = 0; i < 4; ++i) {
            bool is = (v == id[i]);
            for (int u : adj[v]) 
                if (u == id[i])
                    is = true;
            if (!is)
                dead[i] = true;
        }
    } else {
        for (int i = 0; i < 4; ++i) if (id[i] != v)
            dead[i] = true;
    }
}

void Link(int a, int b) {
    deg[a]++, deg[b]++;
    adj[a].pb(b), adj[b].pb(a);
    if (deg[a] >= 3) {
        if (!grt)
            gen(a), grt = true;
        else
            upd(a);
    }
    if (deg[b] >= 3) {
        if (!grt)
            gen(b), grt = true;
        else
            upd(b);
    }
    if (grt) {
        for (int i = 0; i < 4; ++i) if (a != id[i] && b != id[i]) {
            p[i].Union(a, b);
        }
    } else {
        edge.eb(a, b);
        if (ord.Union(a, b)) {
            if (mx == n)
                mx = ord.sz[ord.Find(a)];
            else
                mx = 0;
        }
    }
}

int CountCritical() {
    if (grt) {
        int ans = 0;
        for (int i = 0; i < 4; ++i) if (!dead[i])
            ans += !p[i].cyc;
        return ans;
    } else {
        return mx;
    }
}

/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1
*/
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23780 KB Output is correct
2 Correct 15 ms 24204 KB Output is correct
3 Correct 17 ms 24324 KB Output is correct
4 Correct 16 ms 23884 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 15 ms 24388 KB Output is correct
7 Correct 13 ms 24012 KB Output is correct
8 Correct 15 ms 24200 KB Output is correct
9 Correct 17 ms 24396 KB Output is correct
10 Correct 16 ms 24344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 463 ms 73568 KB Output is correct
2 Correct 1302 ms 96028 KB Output is correct
3 Correct 2015 ms 106936 KB Output is correct
4 Correct 1049 ms 119296 KB Output is correct
5 Correct 1074 ms 119460 KB Output is correct
6 Correct 1059 ms 117460 KB Output is correct
7 Correct 1873 ms 105756 KB Output is correct
8 Correct 1427 ms 110864 KB Output is correct
9 Correct 1455 ms 117868 KB Output is correct
10 Correct 831 ms 116844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23780 KB Output is correct
2 Correct 15 ms 24204 KB Output is correct
3 Correct 17 ms 24324 KB Output is correct
4 Correct 16 ms 23884 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 15 ms 24388 KB Output is correct
7 Correct 13 ms 24012 KB Output is correct
8 Correct 15 ms 24200 KB Output is correct
9 Correct 17 ms 24396 KB Output is correct
10 Correct 16 ms 24344 KB Output is correct
11 Correct 18 ms 24324 KB Output is correct
12 Correct 19 ms 24844 KB Output is correct
13 Correct 22 ms 24772 KB Output is correct
14 Correct 18 ms 24672 KB Output is correct
15 Correct 19 ms 24904 KB Output is correct
16 Correct 17 ms 24784 KB Output is correct
17 Correct 18 ms 24756 KB Output is correct
18 Correct 20 ms 25164 KB Output is correct
19 Correct 17 ms 24912 KB Output is correct
20 Correct 19 ms 24764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23780 KB Output is correct
2 Correct 15 ms 24204 KB Output is correct
3 Correct 17 ms 24324 KB Output is correct
4 Correct 16 ms 23884 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 15 ms 24388 KB Output is correct
7 Correct 13 ms 24012 KB Output is correct
8 Correct 15 ms 24200 KB Output is correct
9 Correct 17 ms 24396 KB Output is correct
10 Correct 16 ms 24344 KB Output is correct
11 Correct 18 ms 24324 KB Output is correct
12 Correct 19 ms 24844 KB Output is correct
13 Correct 22 ms 24772 KB Output is correct
14 Correct 18 ms 24672 KB Output is correct
15 Correct 19 ms 24904 KB Output is correct
16 Correct 17 ms 24784 KB Output is correct
17 Correct 18 ms 24756 KB Output is correct
18 Correct 20 ms 25164 KB Output is correct
19 Correct 17 ms 24912 KB Output is correct
20 Correct 19 ms 24764 KB Output is correct
21 Correct 32 ms 27728 KB Output is correct
22 Correct 45 ms 29784 KB Output is correct
23 Correct 52 ms 31408 KB Output is correct
24 Correct 94 ms 30152 KB Output is correct
25 Correct 36 ms 28640 KB Output is correct
26 Correct 55 ms 30948 KB Output is correct
27 Correct 54 ms 31884 KB Output is correct
28 Correct 77 ms 31452 KB Output is correct
29 Correct 64 ms 30388 KB Output is correct
30 Correct 67 ms 33112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23780 KB Output is correct
2 Correct 15 ms 24204 KB Output is correct
3 Correct 17 ms 24324 KB Output is correct
4 Correct 16 ms 23884 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 15 ms 24388 KB Output is correct
7 Correct 13 ms 24012 KB Output is correct
8 Correct 15 ms 24200 KB Output is correct
9 Correct 17 ms 24396 KB Output is correct
10 Correct 16 ms 24344 KB Output is correct
11 Correct 463 ms 73568 KB Output is correct
12 Correct 1302 ms 96028 KB Output is correct
13 Correct 2015 ms 106936 KB Output is correct
14 Correct 1049 ms 119296 KB Output is correct
15 Correct 1074 ms 119460 KB Output is correct
16 Correct 1059 ms 117460 KB Output is correct
17 Correct 1873 ms 105756 KB Output is correct
18 Correct 1427 ms 110864 KB Output is correct
19 Correct 1455 ms 117868 KB Output is correct
20 Correct 831 ms 116844 KB Output is correct
21 Correct 18 ms 24324 KB Output is correct
22 Correct 19 ms 24844 KB Output is correct
23 Correct 22 ms 24772 KB Output is correct
24 Correct 18 ms 24672 KB Output is correct
25 Correct 19 ms 24904 KB Output is correct
26 Correct 17 ms 24784 KB Output is correct
27 Correct 18 ms 24756 KB Output is correct
28 Correct 20 ms 25164 KB Output is correct
29 Correct 17 ms 24912 KB Output is correct
30 Correct 19 ms 24764 KB Output is correct
31 Correct 32 ms 27728 KB Output is correct
32 Correct 45 ms 29784 KB Output is correct
33 Correct 52 ms 31408 KB Output is correct
34 Correct 94 ms 30152 KB Output is correct
35 Correct 36 ms 28640 KB Output is correct
36 Correct 55 ms 30948 KB Output is correct
37 Correct 54 ms 31884 KB Output is correct
38 Correct 77 ms 31452 KB Output is correct
39 Correct 64 ms 30388 KB Output is correct
40 Correct 67 ms 33112 KB Output is correct
41 Correct 214 ms 59252 KB Output is correct
42 Correct 579 ms 85308 KB Output is correct
43 Correct 311 ms 70668 KB Output is correct
44 Correct 1142 ms 103704 KB Output is correct
45 Correct 1347 ms 96940 KB Output is correct
46 Correct 758 ms 103484 KB Output is correct
47 Correct 933 ms 104824 KB Output is correct
48 Correct 694 ms 89912 KB Output is correct
49 Correct 706 ms 108140 KB Output is correct
50 Correct 751 ms 107328 KB Output is correct
51 Correct 348 ms 66936 KB Output is correct
52 Correct 1014 ms 88680 KB Output is correct
53 Correct 679 ms 90076 KB Output is correct
54 Correct 1275 ms 98540 KB Output is correct
55 Correct 1613 ms 101808 KB Output is correct