답안 #155978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155978 2019-10-02T13:37:53 Z Alexa2001 낙하산 고리들 (IOI12_rings) C++17
100 / 100
917 ms 62064 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e6 + 5;

int n;
bool big = 0, cycle = 0;
vector<int> cand;
vector<pair<int,int>> edges;

int grad[5][Nmax];
bool ok[Nmax];
int ans;


struct FO
{
    int t[Nmax];

    void init()
    {
        int i;
        for(i=0; i<n; ++i) t[i] = i;
    }

    int boss(int x)
    {
        if(t[x] == x) return x;
        return t[x] = boss(t[x]);
    }

    bool unite(int x, int y)
    {
        x = boss(x); y = boss(y);
        if(x == y) return 0;
        t[x] = y;
        return 1;
    }
} forest[5];

void Init(int N)
{
    n = N;
    ans = n;
    forest[4].init();

    int i, j;
    for(i=0; i<n; ++i)
        for(j=0; j<5; ++j)
            grad[j][i] = 0, ok[i] = 0;
}

void transf(int node)
{
    big = 1;

    int i;
    for(auto it : edges)
        if(it.first == node)
            cand.push_back(it.second);
        else if(it.second == node)
            cand.push_back(it.first);

    cand.push_back(node);

    int id = -1;
    for(auto el : cand)
    {
        ++id;
        ok[el] = 1;
        forest[id].init();

        for(auto it : edges)
            if(it.first != el && it.second != el)
            {
                ++grad[id][it.first], ++grad[id][it.second];
                ok[el] &= forest[id].unite(it.first, it.second);
            }
    }

    ans = 0;
    id = -1;
    for(auto it : cand)
    {
        ++id;
        for(i=0; i<n; ++i)
            ok[it] &= (grad[id][i] <= 2);

        if(ok[it]) ++ans;
    }
}

void Link(int A, int B)
{
    edges.push_back({A, B});

    if(!big)
    {
        ++grad[4][A];
        ++grad[4][B];

        if(grad[4][A] == 3) transf(A);
            else if(grad[4][B] == 3) transf(B);
                else
        if(!forest[4].unite(A, B))
        {
            if(!cycle)
            {
                cycle = 1;
                int i;
                ans = 0;
                for(i=0; i<n; ++i)
                    if(forest[4].boss(i) == forest[4].boss(A)) ok[i] = 1, ++ans;
            }
            else ans = 0;
        }
        return;
    }

    int id = -1;
    for(auto el : cand)
    {
        ++id;
        if(!ok[el]) continue;

        if(el != A && el != B)
        {
            ++grad[id][A];
            ++grad[id][B];

            ans --;

            ok[el] &= forest[id].unite(A, B);
            ok[el] &= (grad[id][A] <= 2 && grad[id][B] <= 2);

            ans += ok[el];
        }
    }
}

int CountCritical()
{
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 24280 KB Output is correct
2 Correct 465 ms 49628 KB Output is correct
3 Correct 343 ms 60700 KB Output is correct
4 Correct 579 ms 46216 KB Output is correct
5 Correct 596 ms 46232 KB Output is correct
6 Correct 553 ms 45508 KB Output is correct
7 Correct 327 ms 59860 KB Output is correct
8 Correct 917 ms 58196 KB Output is correct
9 Correct 833 ms 62064 KB Output is correct
10 Correct 457 ms 45640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 7 ms 1144 KB Output is correct
13 Correct 6 ms 1144 KB Output is correct
14 Correct 5 ms 1080 KB Output is correct
15 Correct 5 ms 1528 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 6 ms 1144 KB Output is correct
18 Correct 6 ms 1656 KB Output is correct
19 Correct 5 ms 1016 KB Output is correct
20 Correct 6 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 7 ms 1144 KB Output is correct
13 Correct 6 ms 1144 KB Output is correct
14 Correct 5 ms 1080 KB Output is correct
15 Correct 5 ms 1528 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 6 ms 1144 KB Output is correct
18 Correct 6 ms 1656 KB Output is correct
19 Correct 5 ms 1016 KB Output is correct
20 Correct 6 ms 1144 KB Output is correct
21 Correct 17 ms 2552 KB Output is correct
22 Correct 27 ms 3816 KB Output is correct
23 Correct 33 ms 4596 KB Output is correct
24 Correct 35 ms 5556 KB Output is correct
25 Correct 17 ms 4984 KB Output is correct
26 Correct 35 ms 5968 KB Output is correct
27 Correct 37 ms 4852 KB Output is correct
28 Correct 36 ms 6004 KB Output is correct
29 Correct 30 ms 5624 KB Output is correct
30 Correct 39 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 211 ms 24280 KB Output is correct
12 Correct 465 ms 49628 KB Output is correct
13 Correct 343 ms 60700 KB Output is correct
14 Correct 579 ms 46216 KB Output is correct
15 Correct 596 ms 46232 KB Output is correct
16 Correct 553 ms 45508 KB Output is correct
17 Correct 327 ms 59860 KB Output is correct
18 Correct 917 ms 58196 KB Output is correct
19 Correct 833 ms 62064 KB Output is correct
20 Correct 457 ms 45640 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 7 ms 1144 KB Output is correct
23 Correct 6 ms 1144 KB Output is correct
24 Correct 5 ms 1080 KB Output is correct
25 Correct 5 ms 1528 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 6 ms 1144 KB Output is correct
28 Correct 6 ms 1656 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 6 ms 1144 KB Output is correct
31 Correct 17 ms 2552 KB Output is correct
32 Correct 27 ms 3816 KB Output is correct
33 Correct 33 ms 4596 KB Output is correct
34 Correct 35 ms 5556 KB Output is correct
35 Correct 17 ms 4984 KB Output is correct
36 Correct 35 ms 5968 KB Output is correct
37 Correct 37 ms 4852 KB Output is correct
38 Correct 36 ms 6004 KB Output is correct
39 Correct 30 ms 5624 KB Output is correct
40 Correct 39 ms 4984 KB Output is correct
41 Correct 177 ms 20196 KB Output is correct
42 Correct 435 ms 46688 KB Output is correct
43 Correct 240 ms 43252 KB Output is correct
44 Correct 330 ms 56920 KB Output is correct
45 Correct 444 ms 57188 KB Output is correct
46 Correct 430 ms 39552 KB Output is correct
47 Correct 476 ms 40192 KB Output is correct
48 Correct 288 ms 51420 KB Output is correct
49 Correct 410 ms 43220 KB Output is correct
50 Correct 409 ms 42584 KB Output is correct
51 Correct 232 ms 38404 KB Output is correct
52 Correct 322 ms 46420 KB Output is correct
53 Correct 261 ms 50804 KB Output is correct
54 Correct 690 ms 51176 KB Output is correct
55 Correct 476 ms 55108 KB Output is correct