Submission #817695

# Submission time Handle Problem Language Result Execution time Memory
817695 2023-08-09T15:06:01 Z annabeth9680 Parachute rings (IOI12_rings) C++17
100 / 100
1441 ms 125124 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+20;
int deg[MAXN], ha[MAXN], hb[MAXN],N;
int cur,num,cycnum,cycl;
vector<int> adj[MAXN];
struct dsu{
    int d[MAXN],sz[MAXN];
    void init(int N){
        for(int i = 0;i<N;++i){
            d[i] = i;
            sz[i] = 1;
        }
    }
    int finden(int x){
        return (x == d[x] ? x : d[x] = finden(d[x]));
    }
    int s(int x) {return sz[finden(x)];}
    bool unite(int x, int y){
        x = finden(x); y = finden(y);
        if(x == y) return false;
        d[x] = y; sz[y] += sz[x];
        return true;
    }
}DSU;
struct fall{
    dsu D; int u; int deg[MAXN]; bool ok;
    void init(int v){
        u = v; ok = true;
        fill(deg,deg+N,0); D.init(N);
        for(int i = 0;i<cur;++i){
            if(ha[i] == u || hb[i] == u) continue;
            deg[ha[i]]++; deg[hb[i]]++;
            if(deg[ha[i]] >= 3 || deg[hb[i]] >= 3) ok = false;
            if(!D.unite(ha[i],hb[i])) ok = false;
        }
    }
    void link(){
        int pos = cur-1;
        if(ha[pos] == u || hb[pos] == u) return;
        int a = ha[pos], b = hb[pos];
        deg[a]++; deg[b]++;
        if(deg[a] >= 3 || deg[b] >= 3) ok = false;
        if(!D.unite(a,b)) ok = false;
    }
    bool check(){
        return ok;
    }
}falls[4];
void Init(int n){
    N = n; DSU.init(N);
}
bool good = false;
void Link(int A, int B){
    deg[A]++; deg[B]++; ha[cur] = A; hb[cur] = B; cur++;
    adj[A].push_back(B); adj[B].push_back(A);
    if(good){
        for(int i = 0;i<num;++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.s(A);
        }
        return;
    }
    good = true;
    falls[num++].init(u);
    for(auto v : adj[u]){
        falls[num++].init(v);
    }
}
int CountCritical(){
    if(good){
        int ans = 0;
        for(int i = 0;i<num;++i){
            if(falls[i].check()){
                ans++;
            }
        }
        return ans;
    }
    else{
        if(cycnum >= 2) return 0;
        if(cycnum == 1) return cycl;
        return N;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 24368 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 13 ms 23816 KB Output is correct
5 Correct 13 ms 23964 KB Output is correct
6 Correct 14 ms 24176 KB Output is correct
7 Correct 13 ms 24148 KB Output is correct
8 Correct 15 ms 24096 KB Output is correct
9 Correct 15 ms 24436 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 285 ms 50508 KB Output is correct
2 Correct 901 ms 102408 KB Output is correct
3 Correct 1441 ms 117464 KB Output is correct
4 Correct 835 ms 74828 KB Output is correct
5 Correct 841 ms 74884 KB Output is correct
6 Correct 824 ms 73540 KB Output is correct
7 Correct 1354 ms 116604 KB Output is correct
8 Correct 1024 ms 115648 KB Output is correct
9 Correct 1063 ms 121792 KB Output is correct
10 Correct 544 ms 73292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 24368 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 13 ms 23816 KB Output is correct
5 Correct 13 ms 23964 KB Output is correct
6 Correct 14 ms 24176 KB Output is correct
7 Correct 13 ms 24148 KB Output is correct
8 Correct 15 ms 24096 KB Output is correct
9 Correct 15 ms 24436 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 16 ms 24944 KB Output is correct
13 Correct 16 ms 24976 KB Output is correct
14 Correct 15 ms 24772 KB Output is correct
15 Correct 16 ms 25296 KB Output is correct
16 Correct 16 ms 24420 KB Output is correct
17 Correct 16 ms 24944 KB Output is correct
18 Correct 17 ms 25684 KB Output is correct
19 Correct 17 ms 24404 KB Output is correct
20 Correct 16 ms 25044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 24368 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 13 ms 23816 KB Output is correct
5 Correct 13 ms 23964 KB Output is correct
6 Correct 14 ms 24176 KB Output is correct
7 Correct 13 ms 24148 KB Output is correct
8 Correct 15 ms 24096 KB Output is correct
9 Correct 15 ms 24436 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 16 ms 24944 KB Output is correct
13 Correct 16 ms 24976 KB Output is correct
14 Correct 15 ms 24772 KB Output is correct
15 Correct 16 ms 25296 KB Output is correct
16 Correct 16 ms 24420 KB Output is correct
17 Correct 16 ms 24944 KB Output is correct
18 Correct 17 ms 25684 KB Output is correct
19 Correct 17 ms 24404 KB Output is correct
20 Correct 16 ms 25044 KB Output is correct
21 Correct 27 ms 26060 KB Output is correct
22 Correct 34 ms 27212 KB Output is correct
23 Correct 39 ms 28236 KB Output is correct
24 Correct 57 ms 32068 KB Output is correct
25 Correct 26 ms 30336 KB Output is correct
26 Correct 49 ms 32948 KB Output is correct
27 Correct 42 ms 29236 KB Output is correct
28 Correct 55 ms 33528 KB Output is correct
29 Correct 45 ms 32268 KB Output is correct
30 Correct 45 ms 29980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 24368 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 13 ms 23816 KB Output is correct
5 Correct 13 ms 23964 KB Output is correct
6 Correct 14 ms 24176 KB Output is correct
7 Correct 13 ms 24148 KB Output is correct
8 Correct 15 ms 24096 KB Output is correct
9 Correct 15 ms 24436 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 285 ms 50508 KB Output is correct
12 Correct 901 ms 102408 KB Output is correct
13 Correct 1441 ms 117464 KB Output is correct
14 Correct 835 ms 74828 KB Output is correct
15 Correct 841 ms 74884 KB Output is correct
16 Correct 824 ms 73540 KB Output is correct
17 Correct 1354 ms 116604 KB Output is correct
18 Correct 1024 ms 115648 KB Output is correct
19 Correct 1063 ms 121792 KB Output is correct
20 Correct 544 ms 73292 KB Output is correct
21 Correct 14 ms 24404 KB Output is correct
22 Correct 16 ms 24944 KB Output is correct
23 Correct 16 ms 24976 KB Output is correct
24 Correct 15 ms 24772 KB Output is correct
25 Correct 16 ms 25296 KB Output is correct
26 Correct 16 ms 24420 KB Output is correct
27 Correct 16 ms 24944 KB Output is correct
28 Correct 17 ms 25684 KB Output is correct
29 Correct 17 ms 24404 KB Output is correct
30 Correct 16 ms 25044 KB Output is correct
31 Correct 27 ms 26060 KB Output is correct
32 Correct 34 ms 27212 KB Output is correct
33 Correct 39 ms 28236 KB Output is correct
34 Correct 57 ms 32068 KB Output is correct
35 Correct 26 ms 30336 KB Output is correct
36 Correct 49 ms 32948 KB Output is correct
37 Correct 42 ms 29236 KB Output is correct
38 Correct 55 ms 33528 KB Output is correct
39 Correct 45 ms 32268 KB Output is correct
40 Correct 45 ms 29980 KB Output is correct
41 Correct 155 ms 43276 KB Output is correct
42 Correct 398 ms 99348 KB Output is correct
43 Correct 242 ms 85624 KB Output is correct
44 Correct 819 ms 125124 KB Output is correct
45 Correct 949 ms 116968 KB Output is correct
46 Correct 523 ms 77940 KB Output is correct
47 Correct 690 ms 78888 KB Output is correct
48 Correct 506 ms 107968 KB Output is correct
49 Correct 525 ms 77012 KB Output is correct
50 Correct 555 ms 76572 KB Output is correct
51 Correct 300 ms 80280 KB Output is correct
52 Correct 748 ms 105780 KB Output is correct
53 Correct 541 ms 108432 KB Output is correct
54 Correct 937 ms 114300 KB Output is correct
55 Correct 1145 ms 122260 KB Output is correct