Submission #589392

# Submission time Handle Problem Language Result Execution time Memory
589392 2022-07-04T14:37:36 Z TheScrasse Parachute rings (IOI12_rings) C++17
100 / 100
1682 ms 216352 KB
#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define nf endl
#define ll int
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e9
#define mod 998244353
#define maxn 1000010

ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
ll ms[5], status;
vector<array<ll, 2>> el;

struct graph {
    ll dg[maxn], cn3, cyc, pr[maxn], sz[maxn];
    vector<ll> adj[maxn];

    graph() {
        ll i;
        for (i = 1; i <= n; i++) {
            dg[i] = 0; pr[i] = i; sz[i] = 1;
        }
        cn3 = 0; cyc = 0;
    }

    ll find(ll x) {
        if (x == pr[x]) return x;
        return pr[x] = find(pr[x]);
    }

    bool same(ll a, ll b) {
        return (find(a) == find(b));
    }

    void onion(ll a, ll b) {
        a = find(a); b = find(b);
        if (a == b) {
            cyc++; res = sz[a]; return;
        }
        if (sz[a] < sz[b]) swap(a, b);
        pr[b] = a; sz[a] += sz[b];
    }

    void upd(ll p, ll x) {
        cn3 -= (dg[p] >= 3);
        dg[p] += x;
        cn3 += (dg[p] >= 3);
    }
};

vector<graph> gr;

void ins(ll p, ll a, ll b) {
    if (ms[p] == a || ms[p] == b) return;
    gr[p].upd(a, 1); gr[p].upd(b, 1);
    if (p == 0) gr[p].adj[a].pb(b), gr[p].adj[b].pb(a);
    gr[p].onion(a, b);
}

void Init(int N_) {
    n = N_;
    gr.resize(5);
    // gr[0] = graph(); gr[1] = graph(); gr[2] = graph(); gr[3] = graph(); gr[4] = graph();
}

void Link(int A, int B) {
    a = A + 1; b = B + 1;
    el.pb({a, b});
    if (status == 0) ins(0, a, b);
    else if (status == 2) ins(1, a, b);
    else for (i = 0; i <= 4; i++) ins(i, a, b);

    if (status == 0) {
        if (gr[0].dg[b] >= 3) swap(a, b);
        if (gr[0].dg[a] >= 3) {
            status = 1;
            ms[1] = a; ms[2] = gr[0].adj[a][0]; ms[3] = gr[0].adj[a][1]; ms[4] = gr[0].adj[a][2];
            gr.resize(1);
            gr.resize(5);
            // gr[1] = graph(); gr[2] = graph(); gr[3] = graph(); gr[4] = graph();
            for (auto [x, y] : el) {
                for (i = 1; i <= 4; i++) ins(i, x, y);
            }
        }
    }

    if (gr[0].dg[a] == 4 || gr[0].dg[b] == 4) status = 2;
}

int CountCritical() {
    // cout << "status =" _ status _ gr[0].cyc << nl;

    if (status == 0) {
        if (gr[0].cyc == 0) return n;
        if (gr[0].cyc == 1) return res;
        return 0;
    }

    res = 0;
    for (i = 1; i <= 4; i++) {
        if (gr[i].cyc + gr[i].cn3 == 0) res++;
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 117708 KB Output is correct
2 Correct 76 ms 118216 KB Output is correct
3 Correct 69 ms 118252 KB Output is correct
4 Correct 53 ms 117832 KB Output is correct
5 Correct 59 ms 118088 KB Output is correct
6 Correct 60 ms 118392 KB Output is correct
7 Correct 84 ms 118112 KB Output is correct
8 Correct 55 ms 118192 KB Output is correct
9 Correct 72 ms 118364 KB Output is correct
10 Correct 82 ms 118320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 414 ms 168632 KB Output is correct
2 Correct 722 ms 188088 KB Output is correct
3 Correct 502 ms 185396 KB Output is correct
4 Correct 1054 ms 215420 KB Output is correct
5 Correct 1018 ms 215612 KB Output is correct
6 Correct 1012 ms 213872 KB Output is correct
7 Correct 556 ms 185988 KB Output is correct
8 Correct 1604 ms 210064 KB Output is correct
9 Correct 1682 ms 216352 KB Output is correct
10 Correct 713 ms 214116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 117708 KB Output is correct
2 Correct 76 ms 118216 KB Output is correct
3 Correct 69 ms 118252 KB Output is correct
4 Correct 53 ms 117832 KB Output is correct
5 Correct 59 ms 118088 KB Output is correct
6 Correct 60 ms 118392 KB Output is correct
7 Correct 84 ms 118112 KB Output is correct
8 Correct 55 ms 118192 KB Output is correct
9 Correct 72 ms 118364 KB Output is correct
10 Correct 82 ms 118320 KB Output is correct
11 Correct 75 ms 118284 KB Output is correct
12 Correct 83 ms 118788 KB Output is correct
13 Correct 82 ms 118828 KB Output is correct
14 Correct 76 ms 118512 KB Output is correct
15 Correct 94 ms 119076 KB Output is correct
16 Correct 59 ms 118776 KB Output is correct
17 Correct 79 ms 118776 KB Output is correct
18 Correct 93 ms 119336 KB Output is correct
19 Correct 74 ms 118920 KB Output is correct
20 Correct 81 ms 118924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 117708 KB Output is correct
2 Correct 76 ms 118216 KB Output is correct
3 Correct 69 ms 118252 KB Output is correct
4 Correct 53 ms 117832 KB Output is correct
5 Correct 59 ms 118088 KB Output is correct
6 Correct 60 ms 118392 KB Output is correct
7 Correct 84 ms 118112 KB Output is correct
8 Correct 55 ms 118192 KB Output is correct
9 Correct 72 ms 118364 KB Output is correct
10 Correct 82 ms 118320 KB Output is correct
11 Correct 75 ms 118284 KB Output is correct
12 Correct 83 ms 118788 KB Output is correct
13 Correct 82 ms 118828 KB Output is correct
14 Correct 76 ms 118512 KB Output is correct
15 Correct 94 ms 119076 KB Output is correct
16 Correct 59 ms 118776 KB Output is correct
17 Correct 79 ms 118776 KB Output is correct
18 Correct 93 ms 119336 KB Output is correct
19 Correct 74 ms 118920 KB Output is correct
20 Correct 81 ms 118924 KB Output is correct
21 Correct 78 ms 122004 KB Output is correct
22 Correct 84 ms 124356 KB Output is correct
23 Correct 98 ms 126192 KB Output is correct
24 Correct 105 ms 123948 KB Output is correct
25 Correct 89 ms 123888 KB Output is correct
26 Correct 97 ms 124220 KB Output is correct
27 Correct 108 ms 126096 KB Output is correct
28 Correct 139 ms 126528 KB Output is correct
29 Correct 114 ms 124580 KB Output is correct
30 Correct 104 ms 127380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 117708 KB Output is correct
2 Correct 76 ms 118216 KB Output is correct
3 Correct 69 ms 118252 KB Output is correct
4 Correct 53 ms 117832 KB Output is correct
5 Correct 59 ms 118088 KB Output is correct
6 Correct 60 ms 118392 KB Output is correct
7 Correct 84 ms 118112 KB Output is correct
8 Correct 55 ms 118192 KB Output is correct
9 Correct 72 ms 118364 KB Output is correct
10 Correct 82 ms 118320 KB Output is correct
11 Correct 414 ms 168632 KB Output is correct
12 Correct 722 ms 188088 KB Output is correct
13 Correct 502 ms 185396 KB Output is correct
14 Correct 1054 ms 215420 KB Output is correct
15 Correct 1018 ms 215612 KB Output is correct
16 Correct 1012 ms 213872 KB Output is correct
17 Correct 556 ms 185988 KB Output is correct
18 Correct 1604 ms 210064 KB Output is correct
19 Correct 1682 ms 216352 KB Output is correct
20 Correct 713 ms 214116 KB Output is correct
21 Correct 75 ms 118284 KB Output is correct
22 Correct 83 ms 118788 KB Output is correct
23 Correct 82 ms 118828 KB Output is correct
24 Correct 76 ms 118512 KB Output is correct
25 Correct 94 ms 119076 KB Output is correct
26 Correct 59 ms 118776 KB Output is correct
27 Correct 79 ms 118776 KB Output is correct
28 Correct 93 ms 119336 KB Output is correct
29 Correct 74 ms 118920 KB Output is correct
30 Correct 81 ms 118924 KB Output is correct
31 Correct 78 ms 122004 KB Output is correct
32 Correct 84 ms 124356 KB Output is correct
33 Correct 98 ms 126192 KB Output is correct
34 Correct 105 ms 123948 KB Output is correct
35 Correct 89 ms 123888 KB Output is correct
36 Correct 97 ms 124220 KB Output is correct
37 Correct 108 ms 126096 KB Output is correct
38 Correct 139 ms 126528 KB Output is correct
39 Correct 114 ms 124580 KB Output is correct
40 Correct 104 ms 127380 KB Output is correct
41 Correct 244 ms 158140 KB Output is correct
42 Correct 766 ms 187152 KB Output is correct
43 Correct 271 ms 175268 KB Output is correct
44 Correct 428 ms 181376 KB Output is correct
45 Correct 552 ms 190332 KB Output is correct
46 Correct 662 ms 199452 KB Output is correct
47 Correct 839 ms 201176 KB Output is correct
48 Correct 386 ms 183672 KB Output is correct
49 Correct 667 ms 208472 KB Output is correct
50 Correct 747 ms 207280 KB Output is correct
51 Correct 275 ms 167612 KB Output is correct
52 Correct 796 ms 190468 KB Output is correct
53 Correct 345 ms 183824 KB Output is correct
54 Correct 1514 ms 197708 KB Output is correct
55 Correct 536 ms 179212 KB Output is correct