답안 #50139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50139 2018-06-07T17:43:55 Z top34051 낙하산 고리들 (IOI12_rings) C++17
100 / 100
826 ms 51584 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) {
    if(cyc>1) return ;

    ++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 k=1;k<=4;++k) {
        for(int i=1;i<=m;++i) {
            if(bad[k]) break;
            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) if(!bad[k]) edge(k,x,y);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 764 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 2 ms 936 KB Output is correct
5 Correct 3 ms 936 KB Output is correct
6 Correct 4 ms 936 KB Output is correct
7 Correct 2 ms 948 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 4 ms 948 KB Output is correct
10 Correct 4 ms 948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 18932 KB Output is correct
2 Correct 456 ms 41412 KB Output is correct
3 Correct 340 ms 51012 KB Output is correct
4 Correct 583 ms 51012 KB Output is correct
5 Correct 615 ms 51012 KB Output is correct
6 Correct 564 ms 51012 KB Output is correct
7 Correct 326 ms 51012 KB Output is correct
8 Correct 727 ms 51012 KB Output is correct
9 Correct 826 ms 51584 KB Output is correct
10 Correct 481 ms 51584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 764 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 2 ms 936 KB Output is correct
5 Correct 3 ms 936 KB Output is correct
6 Correct 4 ms 936 KB Output is correct
7 Correct 2 ms 948 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 4 ms 948 KB Output is correct
10 Correct 4 ms 948 KB Output is correct
11 Correct 3 ms 51584 KB Output is correct
12 Correct 6 ms 51584 KB Output is correct
13 Correct 6 ms 51584 KB Output is correct
14 Correct 4 ms 51584 KB Output is correct
15 Correct 4 ms 51584 KB Output is correct
16 Correct 5 ms 51584 KB Output is correct
17 Correct 6 ms 51584 KB Output is correct
18 Correct 6 ms 51584 KB Output is correct
19 Correct 7 ms 51584 KB Output is correct
20 Correct 5 ms 51584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 764 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 2 ms 936 KB Output is correct
5 Correct 3 ms 936 KB Output is correct
6 Correct 4 ms 936 KB Output is correct
7 Correct 2 ms 948 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 4 ms 948 KB Output is correct
10 Correct 4 ms 948 KB Output is correct
11 Correct 3 ms 51584 KB Output is correct
12 Correct 6 ms 51584 KB Output is correct
13 Correct 6 ms 51584 KB Output is correct
14 Correct 4 ms 51584 KB Output is correct
15 Correct 4 ms 51584 KB Output is correct
16 Correct 5 ms 51584 KB Output is correct
17 Correct 6 ms 51584 KB Output is correct
18 Correct 6 ms 51584 KB Output is correct
19 Correct 7 ms 51584 KB Output is correct
20 Correct 5 ms 51584 KB Output is correct
21 Correct 17 ms 51584 KB Output is correct
22 Correct 26 ms 51584 KB Output is correct
23 Correct 33 ms 51584 KB Output is correct
24 Correct 33 ms 51584 KB Output is correct
25 Correct 16 ms 51584 KB Output is correct
26 Correct 35 ms 51584 KB Output is correct
27 Correct 33 ms 51584 KB Output is correct
28 Correct 34 ms 51584 KB Output is correct
29 Correct 29 ms 51584 KB Output is correct
30 Correct 39 ms 51584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 764 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 2 ms 936 KB Output is correct
5 Correct 3 ms 936 KB Output is correct
6 Correct 4 ms 936 KB Output is correct
7 Correct 2 ms 948 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 4 ms 948 KB Output is correct
10 Correct 4 ms 948 KB Output is correct
11 Correct 232 ms 18932 KB Output is correct
12 Correct 456 ms 41412 KB Output is correct
13 Correct 340 ms 51012 KB Output is correct
14 Correct 583 ms 51012 KB Output is correct
15 Correct 615 ms 51012 KB Output is correct
16 Correct 564 ms 51012 KB Output is correct
17 Correct 326 ms 51012 KB Output is correct
18 Correct 727 ms 51012 KB Output is correct
19 Correct 826 ms 51584 KB Output is correct
20 Correct 481 ms 51584 KB Output is correct
21 Correct 3 ms 51584 KB Output is correct
22 Correct 6 ms 51584 KB Output is correct
23 Correct 6 ms 51584 KB Output is correct
24 Correct 4 ms 51584 KB Output is correct
25 Correct 4 ms 51584 KB Output is correct
26 Correct 5 ms 51584 KB Output is correct
27 Correct 6 ms 51584 KB Output is correct
28 Correct 6 ms 51584 KB Output is correct
29 Correct 7 ms 51584 KB Output is correct
30 Correct 5 ms 51584 KB Output is correct
31 Correct 17 ms 51584 KB Output is correct
32 Correct 26 ms 51584 KB Output is correct
33 Correct 33 ms 51584 KB Output is correct
34 Correct 33 ms 51584 KB Output is correct
35 Correct 16 ms 51584 KB Output is correct
36 Correct 35 ms 51584 KB Output is correct
37 Correct 33 ms 51584 KB Output is correct
38 Correct 34 ms 51584 KB Output is correct
39 Correct 29 ms 51584 KB Output is correct
40 Correct 39 ms 51584 KB Output is correct
41 Correct 200 ms 51584 KB Output is correct
42 Correct 443 ms 51584 KB Output is correct
43 Correct 237 ms 51584 KB Output is correct
44 Correct 325 ms 51584 KB Output is correct
45 Correct 465 ms 51584 KB Output is correct
46 Correct 456 ms 51584 KB Output is correct
47 Correct 502 ms 51584 KB Output is correct
48 Correct 292 ms 51584 KB Output is correct
49 Correct 469 ms 51584 KB Output is correct
50 Correct 472 ms 51584 KB Output is correct
51 Correct 238 ms 51584 KB Output is correct
52 Correct 306 ms 51584 KB Output is correct
53 Correct 279 ms 51584 KB Output is correct
54 Correct 681 ms 51584 KB Output is correct
55 Correct 451 ms 51584 KB Output is correct