Submission #821790

# Submission time Handle Problem Language Result Execution time Memory
821790 2023-08-11T16:40:36 Z annabeth9680 Parachute rings (IOI12_rings) C++17
100 / 100
1399 ms 125252 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+20;
int N,cnt,casenum,cycnum,cycl,deg[MAXN],ha[MAXN],hb[MAXN];
vector<int> adj[MAXN];
struct dsu{
    int rep[MAXN],sz[MAXN];
    void init(int n){
        for(int i = 0;i<n;++i){
            rep[i] = i;
            sz[i] = 1;
        }
    }
    int gro(int x){
        return sz[finden(x)];
    }
    int finden(int x){
        return (rep[x] = (rep[x] == x) ? x : finden(rep[x]));
    }
    bool unite(int x, int y){
        x = finden(x); y = finden(y);
        if(x == y) return false;
        sz[y] += sz[x]; rep[x] = y;
        return true;
    }
}DSU;
struct fall{
    dsu D; int deg[MAXN]; bool ok = true; int u;
    void init(int u){
        fall::u = u;
        D.init(N); fill(deg,deg+N,0);
        for(int i = 0;i<cnt;++i){
            int a = ha[i], b = hb[i];
            if(a == u || b == u) continue;
            deg[a]++; deg[b]++;
            if(!D.unite(a,b)){
                ok = false;
            }
            if(deg[a] >= 3 || deg[b] >= 3){
                ok = false;
            }
        }
    }
    void link(){
        int i = cnt-1;
        int a = ha[i], b = hb[i];
        if(a == u || b == u) return;
        deg[a]++; deg[b]++;
        if(!D.unite(a,b)){
            ok = false;
        }
        if(deg[a] >= 3 || deg[b] >= 3){
            ok = false;
        }
    }
    bool check(){
        return ok;
    }
}falls[4];
void Init(int n){
    N = n;
    DSU.init(N);
}
bool f = false;
void Link(int a, int b){
    ha[cnt] = a; hb[cnt] = b; deg[a]++; deg[b]++; cnt++;
    adj[a].push_back(b); adj[b].push_back(a);
    if(f){
        for(int i = 0;i<casenum;++i) falls[i].link();
        return;
    }
    int u = -1;
    if(deg[a] >= 3) u = a;
    if(deg[b] >= 3) u = b;
    if(u == -1){
        if(!DSU.unite(a,b)){
            cycnum++;
            cycl += DSU.gro(a);
        }
        return;
    }
    f = true;
    falls[casenum++].init(u);
    for(auto v : adj[u]){
        falls[casenum++].init(v);
    }
}
int CountCritical(){
    if(f){
        int ans = 0;
        for(int i = 0;i<casenum;++i){
            if(falls[i].check()){
                ans++;
            }
        }
        return ans;
    }
    if(cycnum >= 2) return 0;
    if(cycnum == 1) return cycl;
    return N;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 24376 KB Output is correct
3 Correct 14 ms 24388 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 12 ms 24020 KB Output is correct
6 Correct 13 ms 24148 KB Output is correct
7 Correct 11 ms 24268 KB Output is correct
8 Correct 16 ms 24128 KB Output is correct
9 Correct 13 ms 24420 KB Output is correct
10 Correct 13 ms 24404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 52464 KB Output is correct
2 Correct 899 ms 104564 KB Output is correct
3 Correct 1399 ms 120096 KB Output is correct
4 Correct 794 ms 76908 KB Output is correct
5 Correct 797 ms 77056 KB Output is correct
6 Correct 772 ms 75560 KB Output is correct
7 Correct 1270 ms 118588 KB Output is correct
8 Correct 996 ms 117648 KB Output is correct
9 Correct 1045 ms 123896 KB Output is correct
10 Correct 565 ms 75388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 24376 KB Output is correct
3 Correct 14 ms 24388 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 12 ms 24020 KB Output is correct
6 Correct 13 ms 24148 KB Output is correct
7 Correct 11 ms 24268 KB Output is correct
8 Correct 16 ms 24128 KB Output is correct
9 Correct 13 ms 24420 KB Output is correct
10 Correct 13 ms 24404 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 15 ms 24964 KB Output is correct
13 Correct 15 ms 24916 KB Output is correct
14 Correct 15 ms 24772 KB Output is correct
15 Correct 14 ms 25320 KB Output is correct
16 Correct 15 ms 24508 KB Output is correct
17 Correct 16 ms 25044 KB Output is correct
18 Correct 15 ms 25744 KB Output is correct
19 Correct 14 ms 24404 KB Output is correct
20 Correct 14 ms 25044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 24376 KB Output is correct
3 Correct 14 ms 24388 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 12 ms 24020 KB Output is correct
6 Correct 13 ms 24148 KB Output is correct
7 Correct 11 ms 24268 KB Output is correct
8 Correct 16 ms 24128 KB Output is correct
9 Correct 13 ms 24420 KB Output is correct
10 Correct 13 ms 24404 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 15 ms 24964 KB Output is correct
13 Correct 15 ms 24916 KB Output is correct
14 Correct 15 ms 24772 KB Output is correct
15 Correct 14 ms 25320 KB Output is correct
16 Correct 15 ms 24508 KB Output is correct
17 Correct 16 ms 25044 KB Output is correct
18 Correct 15 ms 25744 KB Output is correct
19 Correct 14 ms 24404 KB Output is correct
20 Correct 14 ms 25044 KB Output is correct
21 Correct 23 ms 26084 KB Output is correct
22 Correct 34 ms 27384 KB Output is correct
23 Correct 36 ms 28288 KB Output is correct
24 Correct 47 ms 32076 KB Output is correct
25 Correct 24 ms 30304 KB Output is correct
26 Correct 45 ms 32916 KB Output is correct
27 Correct 50 ms 29260 KB Output is correct
28 Correct 49 ms 33632 KB Output is correct
29 Correct 40 ms 32244 KB Output is correct
30 Correct 42 ms 30040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 24376 KB Output is correct
3 Correct 14 ms 24388 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 12 ms 24020 KB Output is correct
6 Correct 13 ms 24148 KB Output is correct
7 Correct 11 ms 24268 KB Output is correct
8 Correct 16 ms 24128 KB Output is correct
9 Correct 13 ms 24420 KB Output is correct
10 Correct 13 ms 24404 KB Output is correct
11 Correct 252 ms 52464 KB Output is correct
12 Correct 899 ms 104564 KB Output is correct
13 Correct 1399 ms 120096 KB Output is correct
14 Correct 794 ms 76908 KB Output is correct
15 Correct 797 ms 77056 KB Output is correct
16 Correct 772 ms 75560 KB Output is correct
17 Correct 1270 ms 118588 KB Output is correct
18 Correct 996 ms 117648 KB Output is correct
19 Correct 1045 ms 123896 KB Output is correct
20 Correct 565 ms 75388 KB Output is correct
21 Correct 14 ms 24404 KB Output is correct
22 Correct 15 ms 24964 KB Output is correct
23 Correct 15 ms 24916 KB Output is correct
24 Correct 15 ms 24772 KB Output is correct
25 Correct 14 ms 25320 KB Output is correct
26 Correct 15 ms 24508 KB Output is correct
27 Correct 16 ms 25044 KB Output is correct
28 Correct 15 ms 25744 KB Output is correct
29 Correct 14 ms 24404 KB Output is correct
30 Correct 14 ms 25044 KB Output is correct
31 Correct 23 ms 26084 KB Output is correct
32 Correct 34 ms 27384 KB Output is correct
33 Correct 36 ms 28288 KB Output is correct
34 Correct 47 ms 32076 KB Output is correct
35 Correct 24 ms 30304 KB Output is correct
36 Correct 45 ms 32916 KB Output is correct
37 Correct 50 ms 29260 KB Output is correct
38 Correct 49 ms 33632 KB Output is correct
39 Correct 40 ms 32244 KB Output is correct
40 Correct 42 ms 30040 KB Output is correct
41 Correct 148 ms 43412 KB Output is correct
42 Correct 390 ms 99268 KB Output is correct
43 Correct 237 ms 85708 KB Output is correct
44 Correct 804 ms 125252 KB Output is correct
45 Correct 905 ms 116936 KB Output is correct
46 Correct 481 ms 77900 KB Output is correct
47 Correct 650 ms 78908 KB Output is correct
48 Correct 499 ms 108028 KB Output is correct
49 Correct 537 ms 77056 KB Output is correct
50 Correct 518 ms 76604 KB Output is correct
51 Correct 278 ms 80208 KB Output is correct
52 Correct 683 ms 105912 KB Output is correct
53 Correct 502 ms 108524 KB Output is correct
54 Correct 909 ms 114240 KB Output is correct
55 Correct 1103 ms 122316 KB Output is correct