답안 #50137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50137 2018-06-07T17:38:29 Z top34051 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1873 ms 51420 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;

int n, m, ok;
pair<int,int> e[maxn];

int cyc, cysz, head0[maxn], deg0[maxn], sz0[maxn];

int ban[5], bad[5], head[5][maxn], deg[5][maxn];

void Init(int _n) {
    n = _n;
    for(int i=1;i<=n;++i) head0[i] = i, sz0[i] = 1;
    for(int k=1;k<=4;++k) {
        for(int i=1;i<=n;++i) head[k][i] = i;
    }
}

int CountCritical() {
    if(!ok) {
        if(cyc==0) return n;
        if(cyc==1) return cysz;
        return 0;
    }
    else {
        int res = 0;
        for(int i=1;i<=4;i++) res += !bad[i];
        return res;
    }
}

int findhead(int k, int x) {
    if(head[k][x]==x) return x;
    return head[k][x] = findhead(k, head[k][x]);
}

int findhead0(int x) {
    if(head0[x]==x) return x;
    return head0[x] = findhead0(head0[x]);
}

void edge(int k, int u, int v) {
    if(ban[k]==u || ban[k]==v) return ;

    ++deg[k][u]; ++deg[k][v];
    if(deg[k][u]==3) bad[k] = 1;
    if(deg[k][v]==3) bad[k] = 1;

    int x = findhead(k,u), y = findhead(k,v);
    if(x==y) bad[k] = 1;
    else head[k][x] = y;
}

void edge0(int u, int v) {
    ++deg0[u]; ++deg0[v];

    int x = findhead0(u), y = findhead0(v);
    if(x==y) {
        ++cyc;
        cysz = sz0[x];
    }
    else {
        sz0[y] += sz0[x];
        head0[x] = y;
    }
}

void build(int x) {
    ok = 1;
    int cur = 0;
    ban[++cur] = x;
    for(int i=1;i<=m;++i) {
        if(e[i].first==x) ban[++cur] = e[i].second;
        if(e[i].second==x) ban[++cur] = e[i].first;
    }
    for(int i=1;i<=m;++i) {
        for(int k=1;k<=4;++k) edge(k,e[i].first,e[i].second);
    }
}

void Link(int x, int y) {
    ++x; ++y;
    e[++m] = {x,y};

    if(!ok) {
        edge0(x,y);
        if(deg0[x]==3) build(x);
        else if(deg0[y]==3) build(y);
    }
    else {
        for(int k=1;k<=4;++k) edge(k,x,y);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 788 KB Output is correct
3 Correct 4 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 788 KB Output is correct
7 Correct 3 ms 808 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 4 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 18852 KB Output is correct
2 Correct 1269 ms 41384 KB Output is correct
3 Correct 1873 ms 51040 KB Output is correct
4 Correct 630 ms 51040 KB Output is correct
5 Correct 614 ms 51040 KB Output is correct
6 Correct 554 ms 51040 KB Output is correct
7 Correct 1674 ms 51040 KB Output is correct
8 Correct 1634 ms 51040 KB Output is correct
9 Correct 1864 ms 51420 KB Output is correct
10 Correct 554 ms 51420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 788 KB Output is correct
3 Correct 4 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 788 KB Output is correct
7 Correct 3 ms 808 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 4 ms 936 KB Output is correct
11 Correct 4 ms 51420 KB Output is correct
12 Correct 6 ms 51420 KB Output is correct
13 Correct 7 ms 51420 KB Output is correct
14 Correct 6 ms 51420 KB Output is correct
15 Correct 5 ms 51420 KB Output is correct
16 Correct 6 ms 51420 KB Output is correct
17 Correct 10 ms 51420 KB Output is correct
18 Correct 8 ms 51420 KB Output is correct
19 Correct 5 ms 51420 KB Output is correct
20 Correct 6 ms 51420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 788 KB Output is correct
3 Correct 4 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 788 KB Output is correct
7 Correct 3 ms 808 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 4 ms 936 KB Output is correct
11 Correct 4 ms 51420 KB Output is correct
12 Correct 6 ms 51420 KB Output is correct
13 Correct 7 ms 51420 KB Output is correct
14 Correct 6 ms 51420 KB Output is correct
15 Correct 5 ms 51420 KB Output is correct
16 Correct 6 ms 51420 KB Output is correct
17 Correct 10 ms 51420 KB Output is correct
18 Correct 8 ms 51420 KB Output is correct
19 Correct 5 ms 51420 KB Output is correct
20 Correct 6 ms 51420 KB Output is correct
21 Correct 17 ms 51420 KB Output is correct
22 Correct 30 ms 51420 KB Output is correct
23 Correct 34 ms 51420 KB Output is correct
24 Correct 48 ms 51420 KB Output is correct
25 Correct 19 ms 51420 KB Output is correct
26 Correct 39 ms 51420 KB Output is correct
27 Correct 36 ms 51420 KB Output is correct
28 Correct 44 ms 51420 KB Output is correct
29 Correct 33 ms 51420 KB Output is correct
30 Correct 40 ms 51420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 788 KB Output is correct
3 Correct 4 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 3 ms 788 KB Output is correct
6 Correct 3 ms 788 KB Output is correct
7 Correct 3 ms 808 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 4 ms 936 KB Output is correct
11 Correct 240 ms 18852 KB Output is correct
12 Correct 1269 ms 41384 KB Output is correct
13 Correct 1873 ms 51040 KB Output is correct
14 Correct 630 ms 51040 KB Output is correct
15 Correct 614 ms 51040 KB Output is correct
16 Correct 554 ms 51040 KB Output is correct
17 Correct 1674 ms 51040 KB Output is correct
18 Correct 1634 ms 51040 KB Output is correct
19 Correct 1864 ms 51420 KB Output is correct
20 Correct 554 ms 51420 KB Output is correct
21 Correct 4 ms 51420 KB Output is correct
22 Correct 6 ms 51420 KB Output is correct
23 Correct 7 ms 51420 KB Output is correct
24 Correct 6 ms 51420 KB Output is correct
25 Correct 5 ms 51420 KB Output is correct
26 Correct 6 ms 51420 KB Output is correct
27 Correct 10 ms 51420 KB Output is correct
28 Correct 8 ms 51420 KB Output is correct
29 Correct 5 ms 51420 KB Output is correct
30 Correct 6 ms 51420 KB Output is correct
31 Correct 17 ms 51420 KB Output is correct
32 Correct 30 ms 51420 KB Output is correct
33 Correct 34 ms 51420 KB Output is correct
34 Correct 48 ms 51420 KB Output is correct
35 Correct 19 ms 51420 KB Output is correct
36 Correct 39 ms 51420 KB Output is correct
37 Correct 36 ms 51420 KB Output is correct
38 Correct 44 ms 51420 KB Output is correct
39 Correct 33 ms 51420 KB Output is correct
40 Correct 40 ms 51420 KB Output is correct
41 Correct 192 ms 51420 KB Output is correct
42 Correct 648 ms 51420 KB Output is correct
43 Correct 318 ms 51420 KB Output is correct
44 Correct 802 ms 51420 KB Output is correct
45 Correct 1147 ms 51420 KB Output is correct
46 Correct 524 ms 51420 KB Output is correct
47 Correct 510 ms 51420 KB Output is correct
48 Correct 690 ms 51420 KB Output is correct
49 Correct 458 ms 51420 KB Output is correct
50 Correct 496 ms 51420 KB Output is correct
51 Correct 381 ms 51420 KB Output is correct
52 Correct 692 ms 51420 KB Output is correct
53 Correct 682 ms 51420 KB Output is correct
54 Correct 1301 ms 51420 KB Output is correct
55 Correct 1399 ms 51420 KB Output is correct