Submission #999495

# Submission time Handle Problem Language Result Execution time Memory
999495 2024-06-15T15:44:46 Z bachhoangxuan Parachute rings (IOI12_rings) C++17
100 / 100
653 ms 81516 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;

int N;
struct dsu{
    bool check=true;
    int cnt,par[maxn],sz[maxn],dd[maxn];
    dsu(){};
    void init(){
        cnt=N;check=true;
        for(int i=0;i<N;i++) par[i]=i,sz[i]=1;
    }
    int findpar(int u){
        if(u!=par[u]) return par[u]=findpar(par[u]);
        return u;
    }
    void unions(int u,int v){
        dd[u]++,dd[v]++;
        if(dd[u]>=3 || dd[v]>=3) check=false,cnt=0;
        u=findpar(u);v=findpar(v);
        if(u==v){
            if(!check) cnt=0;
            else cnt=sz[u];
            check=false;
            return;
        }
        if(sz[u]<sz[v]) swap(u,v);
        sz[u]+=sz[v];par[v]=u;
    }
};
int mx=0;
vector<pair<int,int>> e;
vector<int> V;
dsu D[5],S;

void Init(int N_) {
  N = N_;
  S.init();
}

void Link(int A, int B) {
    S.unions(A,B);
    mx=max({mx,S.dd[A],S.dd[B]});
    e.push_back({A,B});
    if(mx>=3){
        if(V.empty()){
            int x=A;
            if(S.dd[x]!=3) x=B;
            for(auto [u,v]:e) if(u==x || v==x) V.push_back(u^v^x);
            V.push_back(x);
            for(int i=0;i<4;i++){
                D[i].init();
                for(auto [u,v]:e) if(u!=V[i] && v!=V[i]) D[i].unions(u,v);
            }
        }
        else{
            for(int i=0;i<4;i++){
                if(A==V[i] || B==V[i]) continue;
                D[i].unions(A,B);
            }
        }
    }
}

int CountCritical() {
    if(mx<=2) return S.cnt;
    int total=0;
    for(int i=0;i<4;i++){
        total+=D[i].check;
        //if(D[i].check) cout << '*' << V[i] << '\n';
    }
    return total;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 5 ms 31320 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 3 ms 31068 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 31324 KB Output is correct
10 Correct 4 ms 31324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 25776 KB Output is correct
2 Correct 475 ms 70080 KB Output is correct
3 Correct 634 ms 80412 KB Output is correct
4 Correct 194 ms 42420 KB Output is correct
5 Correct 195 ms 42684 KB Output is correct
6 Correct 192 ms 41672 KB Output is correct
7 Correct 653 ms 79796 KB Output is correct
8 Correct 440 ms 80824 KB Output is correct
9 Correct 415 ms 81516 KB Output is correct
10 Correct 180 ms 41208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 5 ms 31320 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 3 ms 31068 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 31324 KB Output is correct
10 Correct 4 ms 31324 KB Output is correct
11 Correct 4 ms 31324 KB Output is correct
12 Correct 5 ms 33460 KB Output is correct
13 Correct 5 ms 33644 KB Output is correct
14 Correct 5 ms 33364 KB Output is correct
15 Correct 5 ms 33372 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 5 ms 33628 KB Output is correct
18 Correct 6 ms 33624 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 5 ms 33560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 5 ms 31320 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 3 ms 31068 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 31324 KB Output is correct
10 Correct 4 ms 31324 KB Output is correct
11 Correct 4 ms 31324 KB Output is correct
12 Correct 5 ms 33460 KB Output is correct
13 Correct 5 ms 33644 KB Output is correct
14 Correct 5 ms 33364 KB Output is correct
15 Correct 5 ms 33372 KB Output is correct
16 Correct 3 ms 15196 KB Output is correct
17 Correct 5 ms 33628 KB Output is correct
18 Correct 6 ms 33624 KB Output is correct
19 Correct 3 ms 15196 KB Output is correct
20 Correct 5 ms 33560 KB Output is correct
21 Correct 9 ms 17884 KB Output is correct
22 Correct 16 ms 18384 KB Output is correct
23 Correct 21 ms 20704 KB Output is correct
24 Correct 24 ms 37084 KB Output is correct
25 Correct 10 ms 38232 KB Output is correct
26 Correct 22 ms 39388 KB Output is correct
27 Correct 18 ms 19164 KB Output is correct
28 Correct 25 ms 39640 KB Output is correct
29 Correct 18 ms 38880 KB Output is correct
30 Correct 20 ms 21196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 5 ms 31320 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14940 KB Output is correct
7 Correct 3 ms 31068 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 31324 KB Output is correct
10 Correct 4 ms 31324 KB Output is correct
11 Correct 100 ms 25776 KB Output is correct
12 Correct 475 ms 70080 KB Output is correct
13 Correct 634 ms 80412 KB Output is correct
14 Correct 194 ms 42420 KB Output is correct
15 Correct 195 ms 42684 KB Output is correct
16 Correct 192 ms 41672 KB Output is correct
17 Correct 653 ms 79796 KB Output is correct
18 Correct 440 ms 80824 KB Output is correct
19 Correct 415 ms 81516 KB Output is correct
20 Correct 180 ms 41208 KB Output is correct
21 Correct 4 ms 31324 KB Output is correct
22 Correct 5 ms 33460 KB Output is correct
23 Correct 5 ms 33644 KB Output is correct
24 Correct 5 ms 33364 KB Output is correct
25 Correct 5 ms 33372 KB Output is correct
26 Correct 3 ms 15196 KB Output is correct
27 Correct 5 ms 33628 KB Output is correct
28 Correct 6 ms 33624 KB Output is correct
29 Correct 3 ms 15196 KB Output is correct
30 Correct 5 ms 33560 KB Output is correct
31 Correct 9 ms 17884 KB Output is correct
32 Correct 16 ms 18384 KB Output is correct
33 Correct 21 ms 20704 KB Output is correct
34 Correct 24 ms 37084 KB Output is correct
35 Correct 10 ms 38232 KB Output is correct
36 Correct 22 ms 39388 KB Output is correct
37 Correct 18 ms 19164 KB Output is correct
38 Correct 25 ms 39640 KB Output is correct
39 Correct 18 ms 38880 KB Output is correct
40 Correct 20 ms 21196 KB Output is correct
41 Correct 71 ms 28436 KB Output is correct
42 Correct 199 ms 72172 KB Output is correct
43 Correct 134 ms 65916 KB Output is correct
44 Correct 400 ms 79888 KB Output is correct
45 Correct 416 ms 77340 KB Output is correct
46 Correct 169 ms 40376 KB Output is correct
47 Correct 177 ms 40840 KB Output is correct
48 Correct 330 ms 71624 KB Output is correct
49 Correct 168 ms 41140 KB Output is correct
50 Correct 160 ms 40636 KB Output is correct
51 Correct 143 ms 65992 KB Output is correct
52 Correct 375 ms 77188 KB Output is correct
53 Correct 315 ms 71624 KB Output is correct
54 Correct 482 ms 78004 KB Output is correct
55 Correct 639 ms 80312 KB Output is correct