답안 #252548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252548 2020-07-25T20:31:17 Z Kubin 낙하산 고리들 (IOI12_rings) C++17
0 / 100
148 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

struct disjoint_sets
{
    vector<size_t> repr, rank;

    disjoint_sets(size_t n) : repr(n), rank(n)
    {
        for(size_t i = 0; i < n; i++)
            repr[i] = i;
    }

    size_t find(size_t v)
    {
        return v == repr[v] ? v : repr[v] = find(repr[v]);
    }

    bool unite(size_t u, size_t v)
    {
        if((u = repr[u]) == (v = repr[v]))
            return false;
        if(rank[u] > rank[v])
            swap(u, v);
        rank[v] += (rank[u] == rank[v]);
        repr[u] = v;
        return true;
    }
};

struct bamboo_forest
{
    bool ok = true;
    disjoint_sets dsets;
    vector<size_t> deg;

    bamboo_forest(size_t n) : dsets(n), deg(n) {}

    bool edge(size_t u, size_t v)
    {
        if(++deg[u] > 2 or ++deg[v] > 2 or not dsets.unite(u, v))
            return ok = false;
        return true;
    }
};

size_t n;
vector<bamboo_forest> F;

void Init(int _n)
{
    n = _n;
    F.resize(n, bamboo_forest(n));
}

void Link(int u, int v)
{
    for(size_t i = 0; i < n; i++)
        if((size_t)u != i and (size_t)v != i)
            F[i].edge(u, v);
}

int CountCritical()
{
    size_t result = 0;
    for(size_t i = 0; i < n; i++)
        result += F[i].ok;
    return result;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Runtime error 143 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 148 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Runtime error 143 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Runtime error 143 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Runtime error 143 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -