답안 #361879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361879 2021-01-31T19:20:14 Z idk321 낙하산 고리들 (IOI12_rings) C++11
100 / 100
2001 ms 209428 KB

#include <vector>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef long long ll;



const int N = 1000005;
const int X = 4;
bool all = true;
bool bad = false;
bool bad2[X];
vector<int> big3;
vector<int> adj[X][N];
int p[X][N];
//int r[3][N];
bool second = false;

int n;

int getR(int x, int a)
{
    if (p[x][a] == a)return a;
    p[x][a] = getR(x, p[x][a]);
    return p[x][a];
}

void join(int x, int a, int b)
{
    a = getR(x, a);
    b = getR(x, b);
    if (a == b) return;
    p[x][a] = b;
}


bool vis[N];
bool onSt[N];
vector<int> st;
vector<int> cycle;
void getCycle(int node, int par)
{
    vis[node] = true;
    onSt[node] = true;
    st.push_back(node);
    for (int next : adj[0][node])
    {
        if (next == par || (vis[next] && !onSt[next])) continue;
        if (onSt[next])
        {
            auto it = st.rbegin();
            while (*it != next)
            {
                cycle.push_back(*it);
                it++;
            }
            cycle.push_back(next);
        } else
        {
            getCycle(next, node);
        }
    }

    st.pop_back();
    onSt[node] = false;
}

void Init(int n_) {
    n = n_;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < X; j++) p[j][i] = i;
    }

}

void Link(int a, int b) {
    if (bad) return;

    if (big3.size() <= X - 1 && !big3.empty())
    {
        second = true;
        int ok = 0;
        adj[0][a].push_back(b);
        adj[0][b].push_back(a);
        for (int l = 1; l <= X - 1; l++)
        {
            if (bad2[l]) continue;
            if (a == big3[l - 1] || b == big3[l - 1]) continue;
            adj[l][a].push_back(b);
            adj[l][b].push_back(a);
            if (getR(l, a) == getR(l, b))
            {

                bad2[l] = true;
                continue;
            }
            join(l, a, b);

            for (int t = 0; t < 2; t++)
            {
                swap(a, b);

                if (adj[l][a].size() >= 3)
                {
                    bad2[l] = true;
                    continue;
                }
            }
            ok += !bad2[l];
        }

    } else
    {

        adj[0] [a].push_back(b);
        adj[0] [b].push_back(a);
        if (getR(0, a) == getR(0, b))
        {
            if (cycle.empty())
            {
                all = false;


                getCycle(a, -1);

                if (big3.empty()) big3 = cycle;
                else
                {
                    vector<int> n3;

                    for (int i : cycle)
                    {
                        for (int j : big3) if (i == j) n3.push_back(i);
                    }

                    big3 = n3;
                }

            } else
            {
                bad = true;
                return;
            }
        }

        join(0, a, b);
        for (int t = 0; t < 2; t++)
        {
            swap(a, b);
            if (adj[0] [a].size() >= 3)
            {
                all = false;
                if (big3.empty())
                {
                    big3.push_back(a);
                    if (adj[0][a].size() == 3)for (int i : adj[0] [a]) big3.push_back(i);
                } else
                {
                    vector<int> n3;
                    for (int i : big3)
                    {
                        bool good = false;
                        if (adj[0][a].size() == 3)for (int j : adj[0] [a]) if (j == i) good = true;
                        if (i == a) good = true;
                        if (good) n3.push_back(i);
                    }
                    big3 = n3;
                }

            }
        }

        if (big3.size() <= X - 1 && !big3.empty())
        {
            for (int l = 1; l <= X - 1; l++)
            {
                if (big3.size() < l)
                {
                    bad2[l] = true;
                } else
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (i == big3[l - 1]) continue;
                        for (int j : adj[0][i]) if (j != big3[l - 1])
                        {
                            adj[l][i].push_back(j);
                            join(l, i, j);
                        }
                    }
                }
            }
        }
    }


    if (!all && big3.size() == 0)
    {
        bad = true;
    }

}

int CountCritical() {
    if (all) return n;
    if (bad) return 0;

    if (!second) return big3.size();



    int res = 0;
    for (int i = 1; i<= X - 1; i++) res += !bad2[i];
    return res;
}

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:181:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  181 |                 if (big3.size() < l)
      |                     ~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 94316 KB Output is correct
2 Correct 67 ms 94700 KB Output is correct
3 Correct 67 ms 94700 KB Output is correct
4 Correct 65 ms 94316 KB Output is correct
5 Correct 65 ms 94700 KB Output is correct
6 Correct 67 ms 94956 KB Output is correct
7 Correct 65 ms 94444 KB Output is correct
8 Correct 65 ms 94588 KB Output is correct
9 Correct 68 ms 94828 KB Output is correct
10 Correct 67 ms 94700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 463 ms 118892 KB Output is correct
2 Correct 1346 ms 157036 KB Output is correct
3 Correct 320 ms 111212 KB Output is correct
4 Correct 1140 ms 143980 KB Output is correct
5 Correct 1291 ms 158856 KB Output is correct
6 Correct 1257 ms 206696 KB Output is correct
7 Correct 314 ms 122732 KB Output is correct
8 Correct 2001 ms 209428 KB Output is correct
9 Correct 1571 ms 185904 KB Output is correct
10 Correct 751 ms 154100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 94316 KB Output is correct
2 Correct 67 ms 94700 KB Output is correct
3 Correct 67 ms 94700 KB Output is correct
4 Correct 65 ms 94316 KB Output is correct
5 Correct 65 ms 94700 KB Output is correct
6 Correct 67 ms 94956 KB Output is correct
7 Correct 65 ms 94444 KB Output is correct
8 Correct 65 ms 94588 KB Output is correct
9 Correct 68 ms 94828 KB Output is correct
10 Correct 67 ms 94700 KB Output is correct
11 Correct 74 ms 95084 KB Output is correct
12 Correct 73 ms 95980 KB Output is correct
13 Correct 81 ms 95724 KB Output is correct
14 Correct 69 ms 94956 KB Output is correct
15 Correct 67 ms 94956 KB Output is correct
16 Correct 68 ms 94956 KB Output is correct
17 Correct 71 ms 94956 KB Output is correct
18 Correct 67 ms 94828 KB Output is correct
19 Correct 70 ms 94956 KB Output is correct
20 Correct 70 ms 95212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 94316 KB Output is correct
2 Correct 67 ms 94700 KB Output is correct
3 Correct 67 ms 94700 KB Output is correct
4 Correct 65 ms 94316 KB Output is correct
5 Correct 65 ms 94700 KB Output is correct
6 Correct 67 ms 94956 KB Output is correct
7 Correct 65 ms 94444 KB Output is correct
8 Correct 65 ms 94588 KB Output is correct
9 Correct 68 ms 94828 KB Output is correct
10 Correct 67 ms 94700 KB Output is correct
11 Correct 74 ms 95084 KB Output is correct
12 Correct 73 ms 95980 KB Output is correct
13 Correct 81 ms 95724 KB Output is correct
14 Correct 69 ms 94956 KB Output is correct
15 Correct 67 ms 94956 KB Output is correct
16 Correct 68 ms 94956 KB Output is correct
17 Correct 71 ms 94956 KB Output is correct
18 Correct 67 ms 94828 KB Output is correct
19 Correct 70 ms 94956 KB Output is correct
20 Correct 70 ms 95212 KB Output is correct
21 Correct 91 ms 96620 KB Output is correct
22 Correct 94 ms 97772 KB Output is correct
23 Correct 103 ms 98796 KB Output is correct
24 Correct 131 ms 99564 KB Output is correct
25 Correct 79 ms 96512 KB Output is correct
26 Correct 127 ms 100844 KB Output is correct
27 Correct 106 ms 99180 KB Output is correct
28 Correct 113 ms 99948 KB Output is correct
29 Correct 89 ms 96876 KB Output is correct
30 Correct 130 ms 101740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 94316 KB Output is correct
2 Correct 67 ms 94700 KB Output is correct
3 Correct 67 ms 94700 KB Output is correct
4 Correct 65 ms 94316 KB Output is correct
5 Correct 65 ms 94700 KB Output is correct
6 Correct 67 ms 94956 KB Output is correct
7 Correct 65 ms 94444 KB Output is correct
8 Correct 65 ms 94588 KB Output is correct
9 Correct 68 ms 94828 KB Output is correct
10 Correct 67 ms 94700 KB Output is correct
11 Correct 463 ms 118892 KB Output is correct
12 Correct 1346 ms 157036 KB Output is correct
13 Correct 320 ms 111212 KB Output is correct
14 Correct 1140 ms 143980 KB Output is correct
15 Correct 1291 ms 158856 KB Output is correct
16 Correct 1257 ms 206696 KB Output is correct
17 Correct 314 ms 122732 KB Output is correct
18 Correct 2001 ms 209428 KB Output is correct
19 Correct 1571 ms 185904 KB Output is correct
20 Correct 751 ms 154100 KB Output is correct
21 Correct 74 ms 95084 KB Output is correct
22 Correct 73 ms 95980 KB Output is correct
23 Correct 81 ms 95724 KB Output is correct
24 Correct 69 ms 94956 KB Output is correct
25 Correct 67 ms 94956 KB Output is correct
26 Correct 68 ms 94956 KB Output is correct
27 Correct 71 ms 94956 KB Output is correct
28 Correct 67 ms 94828 KB Output is correct
29 Correct 70 ms 94956 KB Output is correct
30 Correct 70 ms 95212 KB Output is correct
31 Correct 91 ms 96620 KB Output is correct
32 Correct 94 ms 97772 KB Output is correct
33 Correct 103 ms 98796 KB Output is correct
34 Correct 131 ms 99564 KB Output is correct
35 Correct 79 ms 96512 KB Output is correct
36 Correct 127 ms 100844 KB Output is correct
37 Correct 106 ms 99180 KB Output is correct
38 Correct 113 ms 99948 KB Output is correct
39 Correct 89 ms 96876 KB Output is correct
40 Correct 130 ms 101740 KB Output is correct
41 Correct 277 ms 114284 KB Output is correct
42 Correct 512 ms 130284 KB Output is correct
43 Correct 350 ms 117716 KB Output is correct
44 Correct 319 ms 122980 KB Output is correct
45 Correct 895 ms 163132 KB Output is correct
46 Correct 722 ms 145704 KB Output is correct
47 Correct 1097 ms 179268 KB Output is correct
48 Correct 311 ms 118636 KB Output is correct
49 Correct 715 ms 146028 KB Output is correct
50 Correct 767 ms 145644 KB Output is correct
51 Correct 411 ms 119916 KB Output is correct
52 Correct 568 ms 140908 KB Output is correct
53 Correct 275 ms 117740 KB Output is correct
54 Correct 1310 ms 169300 KB Output is correct
55 Correct 1495 ms 175844 KB Output is correct