답안 #501089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501089 2022-01-02T10:53:35 Z doowey 낙하산 고리들 (IOI12_rings) C++14
100 / 100
1727 ms 115356 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = (int)1e6 + 5;

int n;
int par[N];
int deg[N];
vector<int> T[N];

int phase;

void Init(int _n) {
    n = _n;
    phase = 0;
    for(int i = 0 ; i < n; i ++ ){
        par[i] = i;
    }
}

int fin(int u){
    if(par[u] == u) return u;
    return par[u]=fin(par[u]);
}

struct graph{
    int P[N];
    int D[N]; // all deg <= 2 + no cycles
    bool valid;
    int disable;
    void init(){
        for(int i = 0; i < n; i ++ ){
            P[i] = i;
        }
        valid = true;
    }
    int finn(int x){
        if(P[x] == x) return x;
        return P[x]=finn(P[x]);
    }
    void add_edge(int u, int v){
        if(u == disable || v == disable) return;
        D[u] ++ ;
        D[v] ++ ;
        if(D[u] >= 3 || D[v] >= 3) valid = false;
        u = finn(u);
        v = finn(v);
        if(u == v) valid = false;
        else P[u] = v;
    }
};

vector<pii> E;
graph Q[4];

int cycle;

void construct(int u){
    for(int i = 0 ; i < 4; i ++ ){
        Q[i].init();
        if(i < 3) Q[i].disable = T[u][i];
        else Q[i].disable = u;
        for(auto x : E){
            Q[i].add_edge(x.fi, x.se);
        }
    }
}

void dfs(int u, int par, int leng, int target){
    if(u == target){
        cycle = leng;
    }
    for(auto x : T[u]){
        if(x == par){
            continue;
        }
        dfs(x, u, leng + 1, target);
    }
}

void Link(int a, int b) {
    if(phase == -1) return;
    E.push_back(mp(a, b));
    deg[a] ++ ;
    deg[b] ++ ;
    T[a].push_back(b);
    T[b].push_back(a);
    if(phase == 0){
        if(fin(a) == fin(b)){
            phase = 1;
            T[a].pop_back();
            T[b].pop_back();

            dfs(a, -1, 1, b);

            T[a].push_back(b);
            T[b].push_back(a);
        }
        else{
            par[fin(a)] = fin(b);
        }

        if(deg[a] == 3){
            construct(a);
            phase = 2;
            return;
        }
        if(deg[b] == 3){
            construct(b);
            phase = 2;
            return;
        }
    }
    else if(phase == 1){
        if(deg[a] == 3){
            construct(a);
            phase = 2;
            return;
        }
        if(deg[b] == 3){
            construct(b);
            phase = 2;
            return;
        }
        if(fin(a) == fin(b)){
            phase = -1;
            return;
        }
        else{
            par[fin(a)] = fin(b);
        }
    }
    else{
        for(int i = 0 ; i < 4; i ++ ){
            Q[i].add_edge(a, b);
        }
    }
}


int CountCritical() {
    if(phase == -1){
        return 0;
    }
    if(phase == 0){
        return n;
    }
    if(phase == 1){
        return cycle;
    }
    if(phase == 2){
        return (Q[0].valid + Q[1].valid + Q[2].valid + Q[3].valid);
    }
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:162:1: warning: control reaches end of non-void function [-Wreturn-type]
  162 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23760 KB Output is correct
2 Correct 14 ms 24212 KB Output is correct
3 Correct 13 ms 24332 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 13 ms 23948 KB Output is correct
6 Correct 13 ms 24140 KB Output is correct
7 Correct 12 ms 24012 KB Output is correct
8 Correct 14 ms 23956 KB Output is correct
9 Correct 13 ms 24252 KB Output is correct
10 Correct 13 ms 24268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 55028 KB Output is correct
2 Correct 976 ms 97052 KB Output is correct
3 Correct 1727 ms 110332 KB Output is correct
4 Correct 855 ms 84152 KB Output is correct
5 Correct 862 ms 84572 KB Output is correct
6 Correct 933 ms 95068 KB Output is correct
7 Correct 1581 ms 108796 KB Output is correct
8 Correct 1060 ms 109488 KB Output is correct
9 Correct 1100 ms 115356 KB Output is correct
10 Correct 579 ms 81180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23760 KB Output is correct
2 Correct 14 ms 24212 KB Output is correct
3 Correct 13 ms 24332 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 13 ms 23948 KB Output is correct
6 Correct 13 ms 24140 KB Output is correct
7 Correct 12 ms 24012 KB Output is correct
8 Correct 14 ms 23956 KB Output is correct
9 Correct 13 ms 24252 KB Output is correct
10 Correct 13 ms 24268 KB Output is correct
11 Correct 14 ms 24212 KB Output is correct
12 Correct 16 ms 24768 KB Output is correct
13 Correct 15 ms 24784 KB Output is correct
14 Correct 14 ms 24524 KB Output is correct
15 Correct 16 ms 24960 KB Output is correct
16 Correct 15 ms 24428 KB Output is correct
17 Correct 16 ms 24768 KB Output is correct
18 Correct 18 ms 25236 KB Output is correct
19 Correct 15 ms 24480 KB Output is correct
20 Correct 15 ms 24780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23760 KB Output is correct
2 Correct 14 ms 24212 KB Output is correct
3 Correct 13 ms 24332 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 13 ms 23948 KB Output is correct
6 Correct 13 ms 24140 KB Output is correct
7 Correct 12 ms 24012 KB Output is correct
8 Correct 14 ms 23956 KB Output is correct
9 Correct 13 ms 24252 KB Output is correct
10 Correct 13 ms 24268 KB Output is correct
11 Correct 14 ms 24212 KB Output is correct
12 Correct 16 ms 24768 KB Output is correct
13 Correct 15 ms 24784 KB Output is correct
14 Correct 14 ms 24524 KB Output is correct
15 Correct 16 ms 24960 KB Output is correct
16 Correct 15 ms 24428 KB Output is correct
17 Correct 16 ms 24768 KB Output is correct
18 Correct 18 ms 25236 KB Output is correct
19 Correct 15 ms 24480 KB Output is correct
20 Correct 15 ms 24780 KB Output is correct
21 Correct 25 ms 25824 KB Output is correct
22 Correct 36 ms 26848 KB Output is correct
23 Correct 43 ms 27740 KB Output is correct
24 Correct 61 ms 30180 KB Output is correct
25 Correct 26 ms 28364 KB Output is correct
26 Correct 50 ms 31036 KB Output is correct
27 Correct 42 ms 28732 KB Output is correct
28 Correct 56 ms 31836 KB Output is correct
29 Correct 42 ms 30184 KB Output is correct
30 Correct 56 ms 29832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23760 KB Output is correct
2 Correct 14 ms 24212 KB Output is correct
3 Correct 13 ms 24332 KB Output is correct
4 Correct 12 ms 23820 KB Output is correct
5 Correct 13 ms 23948 KB Output is correct
6 Correct 13 ms 24140 KB Output is correct
7 Correct 12 ms 24012 KB Output is correct
8 Correct 14 ms 23956 KB Output is correct
9 Correct 13 ms 24252 KB Output is correct
10 Correct 13 ms 24268 KB Output is correct
11 Correct 308 ms 55028 KB Output is correct
12 Correct 976 ms 97052 KB Output is correct
13 Correct 1727 ms 110332 KB Output is correct
14 Correct 855 ms 84152 KB Output is correct
15 Correct 862 ms 84572 KB Output is correct
16 Correct 933 ms 95068 KB Output is correct
17 Correct 1581 ms 108796 KB Output is correct
18 Correct 1060 ms 109488 KB Output is correct
19 Correct 1100 ms 115356 KB Output is correct
20 Correct 579 ms 81180 KB Output is correct
21 Correct 14 ms 24212 KB Output is correct
22 Correct 16 ms 24768 KB Output is correct
23 Correct 15 ms 24784 KB Output is correct
24 Correct 14 ms 24524 KB Output is correct
25 Correct 16 ms 24960 KB Output is correct
26 Correct 15 ms 24428 KB Output is correct
27 Correct 16 ms 24768 KB Output is correct
28 Correct 18 ms 25236 KB Output is correct
29 Correct 15 ms 24480 KB Output is correct
30 Correct 15 ms 24780 KB Output is correct
31 Correct 25 ms 25824 KB Output is correct
32 Correct 36 ms 26848 KB Output is correct
33 Correct 43 ms 27740 KB Output is correct
34 Correct 61 ms 30180 KB Output is correct
35 Correct 26 ms 28364 KB Output is correct
36 Correct 50 ms 31036 KB Output is correct
37 Correct 42 ms 28732 KB Output is correct
38 Correct 56 ms 31836 KB Output is correct
39 Correct 42 ms 30184 KB Output is correct
40 Correct 56 ms 29832 KB Output is correct
41 Correct 175 ms 41300 KB Output is correct
42 Correct 442 ms 82848 KB Output is correct
43 Correct 259 ms 67516 KB Output is correct
44 Correct 826 ms 107012 KB Output is correct
45 Correct 1092 ms 98260 KB Output is correct
46 Correct 545 ms 74064 KB Output is correct
47 Correct 826 ms 83112 KB Output is correct
48 Correct 554 ms 88404 KB Output is correct
49 Correct 547 ms 73092 KB Output is correct
50 Correct 589 ms 72768 KB Output is correct
51 Correct 302 ms 64748 KB Output is correct
52 Correct 749 ms 91348 KB Output is correct
53 Correct 564 ms 88848 KB Output is correct
54 Correct 1024 ms 98628 KB Output is correct
55 Correct 1252 ms 105036 KB Output is correct