답안 #471526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471526 2021-09-09T16:18:25 Z blue 낙하산 고리들 (IOI12_rings) C++17
0 / 100
4000 ms 262148 KB
#include <iostream>
#include <vector>
using namespace std;

struct disjoint_set
{
    int S;
    vector<short> parent;
    vector<short> subtree;

    disjoint_set()
    {
        ;
    }

    disjoint_set(int s)
    {
        S = s;
        parent = vector<short>(S);
        subtree = vector<short>(S);
        for(int i = 0; i < S; i++)
        {
            parent[i] = i;
            subtree[i] = 1;
        }
    }

    int root(int u)
    {
        int v = u;
        while(parent[v] != v) v = parent[v];
        parent[u] = v;
        return v;
    }

    bool connected(int u, int v)
    {
        return root(u) == root(v);
    }

    void join(int u, int v)
    {
        u = root(u);
        v = root(v);
        if(u == v) return;
        if(subtree[u] < subtree[v]) swap(u, v);

        subtree[u] += subtree[v];
        parent[v] = u;
    }
};

const int X = 0;
const int Y = 1;
const int Z = 2;

int state = Z;
int N;


vector<int> Z_critical;
vector< vector<short> > Z_degree;
vector<disjoint_set> DSU;
vector<bool> good;

void Init(int N_)
{
    N = N_;
    for(int i = 0; i < N; i++)
    {
        Z_critical.push_back(i);
        Z_degree.push_back(vector<short>(N, 0));
        DSU.push_back(disjoint_set(N));
        good.push_back(1);
    }
}

void Link(int A, int B)
{
    if(state == Z)
    {
        for(int q = 0; q < (int)Z_critical.size(); q++)
        {
            int z = Z_critical[q];
            if(A == z || B == z)
            {
                continue;
            }
            if(DSU[q].connected(A, B))
            {
                good[q] = 0;
            }
            Z_degree[q][A]++;
            Z_degree[q][B]++;
            if(Z_degree[q][A] > 2 || Z_degree[q][B] > 2)
                good[q] = 0;

            DSU[q].join(A, B);
        }
    }
}

int CountCritical()
{
    int res = 0;
    for(int i = 0; i < N; i++)
    {
        res += good[i];
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3185 ms 103752 KB Output is correct
3 Execution timed out 4094 ms 147808 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 171 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3185 ms 103752 KB Output is correct
3 Execution timed out 4094 ms 147808 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3185 ms 103752 KB Output is correct
3 Execution timed out 4094 ms 147808 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3185 ms 103752 KB Output is correct
3 Execution timed out 4094 ms 147808 KB Time limit exceeded
4 Halted 0 ms 0 KB -