답안 #50138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50138 2018-06-07T17:40:49 Z top34051 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1824 ms 51532 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(bad[k]) return ;

    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 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 5 ms 796 KB Output is correct
3 Correct 5 ms 928 KB Output is correct
4 Correct 2 ms 928 KB Output is correct
5 Correct 3 ms 928 KB Output is correct
6 Correct 4 ms 928 KB Output is correct
7 Correct 2 ms 928 KB Output is correct
8 Correct 3 ms 928 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 18960 KB Output is correct
2 Correct 742 ms 41540 KB Output is correct
3 Correct 360 ms 51012 KB Output is correct
4 Correct 554 ms 51012 KB Output is correct
5 Correct 551 ms 51012 KB Output is correct
6 Correct 563 ms 51012 KB Output is correct
7 Correct 390 ms 51012 KB Output is correct
8 Correct 1527 ms 51012 KB Output is correct
9 Correct 1824 ms 51532 KB Output is correct
10 Correct 521 ms 51532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 796 KB Output is correct
3 Correct 5 ms 928 KB Output is correct
4 Correct 2 ms 928 KB Output is correct
5 Correct 3 ms 928 KB Output is correct
6 Correct 4 ms 928 KB Output is correct
7 Correct 2 ms 928 KB Output is correct
8 Correct 3 ms 928 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 928 KB Output is correct
11 Correct 4 ms 51532 KB Output is correct
12 Correct 6 ms 51532 KB Output is correct
13 Correct 6 ms 51532 KB Output is correct
14 Correct 5 ms 51532 KB Output is correct
15 Correct 5 ms 51532 KB Output is correct
16 Correct 5 ms 51532 KB Output is correct
17 Correct 5 ms 51532 KB Output is correct
18 Correct 8 ms 51532 KB Output is correct
19 Correct 5 ms 51532 KB Output is correct
20 Correct 6 ms 51532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 796 KB Output is correct
3 Correct 5 ms 928 KB Output is correct
4 Correct 2 ms 928 KB Output is correct
5 Correct 3 ms 928 KB Output is correct
6 Correct 4 ms 928 KB Output is correct
7 Correct 2 ms 928 KB Output is correct
8 Correct 3 ms 928 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 928 KB Output is correct
11 Correct 4 ms 51532 KB Output is correct
12 Correct 6 ms 51532 KB Output is correct
13 Correct 6 ms 51532 KB Output is correct
14 Correct 5 ms 51532 KB Output is correct
15 Correct 5 ms 51532 KB Output is correct
16 Correct 5 ms 51532 KB Output is correct
17 Correct 5 ms 51532 KB Output is correct
18 Correct 8 ms 51532 KB Output is correct
19 Correct 5 ms 51532 KB Output is correct
20 Correct 6 ms 51532 KB Output is correct
21 Correct 17 ms 51532 KB Output is correct
22 Correct 29 ms 51532 KB Output is correct
23 Correct 37 ms 51532 KB Output is correct
24 Correct 35 ms 51532 KB Output is correct
25 Correct 17 ms 51532 KB Output is correct
26 Correct 35 ms 51532 KB Output is correct
27 Correct 36 ms 51532 KB Output is correct
28 Correct 34 ms 51532 KB Output is correct
29 Correct 30 ms 51532 KB Output is correct
30 Correct 41 ms 51532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 796 KB Output is correct
3 Correct 5 ms 928 KB Output is correct
4 Correct 2 ms 928 KB Output is correct
5 Correct 3 ms 928 KB Output is correct
6 Correct 4 ms 928 KB Output is correct
7 Correct 2 ms 928 KB Output is correct
8 Correct 3 ms 928 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 928 KB Output is correct
11 Correct 248 ms 18960 KB Output is correct
12 Correct 742 ms 41540 KB Output is correct
13 Correct 360 ms 51012 KB Output is correct
14 Correct 554 ms 51012 KB Output is correct
15 Correct 551 ms 51012 KB Output is correct
16 Correct 563 ms 51012 KB Output is correct
17 Correct 390 ms 51012 KB Output is correct
18 Correct 1527 ms 51012 KB Output is correct
19 Correct 1824 ms 51532 KB Output is correct
20 Correct 521 ms 51532 KB Output is correct
21 Correct 4 ms 51532 KB Output is correct
22 Correct 6 ms 51532 KB Output is correct
23 Correct 6 ms 51532 KB Output is correct
24 Correct 5 ms 51532 KB Output is correct
25 Correct 5 ms 51532 KB Output is correct
26 Correct 5 ms 51532 KB Output is correct
27 Correct 5 ms 51532 KB Output is correct
28 Correct 8 ms 51532 KB Output is correct
29 Correct 5 ms 51532 KB Output is correct
30 Correct 6 ms 51532 KB Output is correct
31 Correct 17 ms 51532 KB Output is correct
32 Correct 29 ms 51532 KB Output is correct
33 Correct 37 ms 51532 KB Output is correct
34 Correct 35 ms 51532 KB Output is correct
35 Correct 17 ms 51532 KB Output is correct
36 Correct 35 ms 51532 KB Output is correct
37 Correct 36 ms 51532 KB Output is correct
38 Correct 34 ms 51532 KB Output is correct
39 Correct 30 ms 51532 KB Output is correct
40 Correct 41 ms 51532 KB Output is correct
41 Correct 182 ms 51532 KB Output is correct
42 Correct 643 ms 51532 KB Output is correct
43 Correct 236 ms 51532 KB Output is correct
44 Correct 348 ms 51532 KB Output is correct
45 Correct 451 ms 51532 KB Output is correct
46 Correct 445 ms 51532 KB Output is correct
47 Correct 500 ms 51532 KB Output is correct
48 Correct 301 ms 51532 KB Output is correct
49 Correct 495 ms 51532 KB Output is correct
50 Correct 463 ms 51532 KB Output is correct
51 Correct 295 ms 51532 KB Output is correct
52 Correct 321 ms 51532 KB Output is correct
53 Correct 274 ms 51532 KB Output is correct
54 Correct 1119 ms 51532 KB Output is correct
55 Correct 503 ms 51532 KB Output is correct