Submission #1111533

# Submission time Handle Problem Language Result Execution time Memory
1111533 2024-11-12T09:21:05 Z baotoan655 Parachute rings (IOI12_rings) C++14
100 / 100
714 ms 118964 KB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define REV(i, b, a) for(int i = (b); i >= (a); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define fi first
#define se second

using namespace std;

const int N = 1e6 + 5;

int n, dsu[N], deg[N], c, sz[N], cy, res;
vector<int> g[N];
vector<pair<int, int>> edge;

int root(int u) {
    if(u == dsu[u]) return u;
    return dsu[u] = root(dsu[u]);
}
struct DSU {
    int rt, fa[N], ans, deg[N];
    int root(int u) {
        if(u == fa[u]) return u;
        return fa[u] = root(fa[u]);
    }
    bool join(int u, int v) {
        if(u == rt || v == rt || ans == 0) return false;
        if(++deg[u] == 3) ans = 0;
        if(++deg[v] == 3) ans = 0;
        u = root(u), v = root(v);
        if(u == v) {
            ans = 0;
            return false;
        }
        fa[u] = v;
        return true;
    }
    void init() {
        ans = 1;
        REP(i, n) fa[i] = i;
        for(auto x : edge) join(x.fi, x.se);
    }
} ds[4];
int q;

void Init(int _n) {
    n = _n;
    REP(i, n) {
        dsu[i] = i, sz[i] = 1;
    }
}
void Link(int u, int v) {
    if(c) REP(i, 4) ds[i].join(u, v);
    else {
        edge.emplace_back(u, v);
        g[u].emplace_back(v);
        g[v].emplace_back(u);
        if(deg[u] + 1 == 3 || deg[v] + 1 == 3) c = 1;
        if(++deg[u] == 3) {
            ds[0].rt = u;
            REP(i, 3) ds[i + 1].rt = g[u][i];
            REP(i, 4) ds[i].init();
            return;
        }
        if(++deg[v] == 3) {
            ds[0].rt = v;
            REP(i, 3) ds[i + 1].rt = g[v][i];
            REP(i, 4) ds[i].init();
            return;
        }
        if(root(u) != root(v)) {
            u = root(u); v = root(v);
            sz[u] += sz[v];
            dsu[v] = u;
        } else {
            res = sz[root(u)];
            ++cy;
        }
    }
}
int CountCritical() {
    if(cy > 1) return 0;
            else if(c) return ds[0].ans + ds[1].ans + ds[2].ans + ds[3].ans;
            else if(cy == 1) return res;
            return n;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26960 KB Output is correct
2 Correct 7 ms 41692 KB Output is correct
3 Correct 7 ms 41552 KB Output is correct
4 Correct 5 ms 26960 KB Output is correct
5 Correct 6 ms 27216 KB Output is correct
6 Correct 6 ms 27472 KB Output is correct
7 Correct 7 ms 41464 KB Output is correct
8 Correct 6 ms 27216 KB Output is correct
9 Correct 8 ms 41552 KB Output is correct
10 Correct 7 ms 41552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 60472 KB Output is correct
2 Correct 296 ms 94552 KB Output is correct
3 Correct 150 ms 80024 KB Output is correct
4 Correct 691 ms 88744 KB Output is correct
5 Correct 714 ms 88964 KB Output is correct
6 Correct 693 ms 87288 KB Output is correct
7 Correct 147 ms 79604 KB Output is correct
8 Correct 505 ms 111652 KB Output is correct
9 Correct 578 ms 118964 KB Output is correct
10 Correct 365 ms 86952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26960 KB Output is correct
2 Correct 7 ms 41692 KB Output is correct
3 Correct 7 ms 41552 KB Output is correct
4 Correct 5 ms 26960 KB Output is correct
5 Correct 6 ms 27216 KB Output is correct
6 Correct 6 ms 27472 KB Output is correct
7 Correct 7 ms 41464 KB Output is correct
8 Correct 6 ms 27216 KB Output is correct
9 Correct 8 ms 41552 KB Output is correct
10 Correct 7 ms 41552 KB Output is correct
11 Correct 7 ms 41552 KB Output is correct
12 Correct 9 ms 42064 KB Output is correct
13 Correct 8 ms 41944 KB Output is correct
14 Correct 7 ms 41564 KB Output is correct
15 Correct 7 ms 41552 KB Output is correct
16 Correct 7 ms 27728 KB Output is correct
17 Correct 7 ms 41744 KB Output is correct
18 Correct 8 ms 41808 KB Output is correct
19 Correct 7 ms 27728 KB Output is correct
20 Correct 8 ms 41808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26960 KB Output is correct
2 Correct 7 ms 41692 KB Output is correct
3 Correct 7 ms 41552 KB Output is correct
4 Correct 5 ms 26960 KB Output is correct
5 Correct 6 ms 27216 KB Output is correct
6 Correct 6 ms 27472 KB Output is correct
7 Correct 7 ms 41464 KB Output is correct
8 Correct 6 ms 27216 KB Output is correct
9 Correct 8 ms 41552 KB Output is correct
10 Correct 7 ms 41552 KB Output is correct
11 Correct 7 ms 41552 KB Output is correct
12 Correct 9 ms 42064 KB Output is correct
13 Correct 8 ms 41944 KB Output is correct
14 Correct 7 ms 41564 KB Output is correct
15 Correct 7 ms 41552 KB Output is correct
16 Correct 7 ms 27728 KB Output is correct
17 Correct 7 ms 41744 KB Output is correct
18 Correct 8 ms 41808 KB Output is correct
19 Correct 7 ms 27728 KB Output is correct
20 Correct 8 ms 41808 KB Output is correct
21 Correct 15 ms 28776 KB Output is correct
22 Correct 23 ms 29932 KB Output is correct
23 Correct 29 ms 30664 KB Output is correct
24 Correct 28 ms 44616 KB Output is correct
25 Correct 16 ms 44112 KB Output is correct
26 Correct 23 ms 45004 KB Output is correct
27 Correct 36 ms 31700 KB Output is correct
28 Correct 21 ms 45136 KB Output is correct
29 Correct 20 ms 45068 KB Output is correct
30 Correct 39 ms 32444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26960 KB Output is correct
2 Correct 7 ms 41692 KB Output is correct
3 Correct 7 ms 41552 KB Output is correct
4 Correct 5 ms 26960 KB Output is correct
5 Correct 6 ms 27216 KB Output is correct
6 Correct 6 ms 27472 KB Output is correct
7 Correct 7 ms 41464 KB Output is correct
8 Correct 6 ms 27216 KB Output is correct
9 Correct 8 ms 41552 KB Output is correct
10 Correct 7 ms 41552 KB Output is correct
11 Correct 229 ms 60472 KB Output is correct
12 Correct 296 ms 94552 KB Output is correct
13 Correct 150 ms 80024 KB Output is correct
14 Correct 691 ms 88744 KB Output is correct
15 Correct 714 ms 88964 KB Output is correct
16 Correct 693 ms 87288 KB Output is correct
17 Correct 147 ms 79604 KB Output is correct
18 Correct 505 ms 111652 KB Output is correct
19 Correct 578 ms 118964 KB Output is correct
20 Correct 365 ms 86952 KB Output is correct
21 Correct 7 ms 41552 KB Output is correct
22 Correct 9 ms 42064 KB Output is correct
23 Correct 8 ms 41944 KB Output is correct
24 Correct 7 ms 41564 KB Output is correct
25 Correct 7 ms 41552 KB Output is correct
26 Correct 7 ms 27728 KB Output is correct
27 Correct 7 ms 41744 KB Output is correct
28 Correct 8 ms 41808 KB Output is correct
29 Correct 7 ms 27728 KB Output is correct
30 Correct 8 ms 41808 KB Output is correct
31 Correct 15 ms 28776 KB Output is correct
32 Correct 23 ms 29932 KB Output is correct
33 Correct 29 ms 30664 KB Output is correct
34 Correct 28 ms 44616 KB Output is correct
35 Correct 16 ms 44112 KB Output is correct
36 Correct 23 ms 45004 KB Output is correct
37 Correct 36 ms 31700 KB Output is correct
38 Correct 21 ms 45136 KB Output is correct
39 Correct 20 ms 45068 KB Output is correct
40 Correct 39 ms 32444 KB Output is correct
41 Correct 118 ms 47288 KB Output is correct
42 Correct 264 ms 89532 KB Output is correct
43 Correct 126 ms 64300 KB Output is correct
44 Correct 146 ms 78920 KB Output is correct
45 Correct 176 ms 78304 KB Output is correct
46 Correct 383 ms 81576 KB Output is correct
47 Correct 500 ms 82212 KB Output is correct
48 Correct 134 ms 75516 KB Output is correct
49 Correct 359 ms 78188 KB Output is correct
50 Correct 485 ms 77736 KB Output is correct
51 Correct 121 ms 69704 KB Output is correct
52 Correct 179 ms 76104 KB Output is correct
53 Correct 120 ms 74340 KB Output is correct
54 Correct 451 ms 100548 KB Output is correct
55 Correct 231 ms 79080 KB Output is correct