답안 #259281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259281 2020-08-07T13:43:44 Z Sorting 낙하산 고리들 (IOI12_rings) C++17
0 / 100
1321 ms 107256 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 1e6 + 3;

int n;
int p[k_N], sz[k_N];

vector<int> adj[k_N], adj2[k_N];

int cnt[k_N], req;
bool ok;

int get_p(int u){
    if(p[u] == u) return u;
    return p[u] = get_p(p[u]);
}

bool unite(int u, int v){
    if(get_p(u) == get_p(v))
        return false;

    if(sz[p[u]] < sz[p[v]])
        swap(u, v);

    sz[p[u]] += sz[p[v]];
    p[p[v]] = p[u];

    return true;
}

void Init(int n_){
    n = n_;

    for(int i = 0; i < n; ++i){
        p[i] = i;
        sz[i] = 1;
        cnt[i] = 0;

        adj[i].clear();
        adj2[i].clear();
    }

    req = 0;
    ok = true;
}

bool dfs(int a, int b, int parent = -1){
    if(a == b){
        cnt[a]++;
        return true;
    }

    for(int to: adj[a]){
        if(to == parent) continue;
        if(dfs(to, b, a)){
            cnt[a]++;
            return true;
        }
    }
    return false;
}

void Link(int a, int b){
    adj2[a].push_back(b);
    adj2[b].push_back(a);

    if(adj2[a].size() >= 4 || adj2[b].size() >= 4) ok = false;
    if(adj2[a].size() == 3) req++;
    if(adj2[b].size() == 3) req++;

    if(!unite(a, b)){
        req++;
        dfs(a, b);
    }
    else{
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
}

int CountCritical(){
    if(!ok) return 0;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int curr_req = cnt[i];
        for(int to: adj2[i])
            curr_req += (adj2[to].size() == 3);
        ans += (req == curr_req);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 47360 KB Output is correct
2 Incorrect 32 ms 47608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 872 ms 86140 KB Output is correct
2 Incorrect 1321 ms 107256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 47360 KB Output is correct
2 Incorrect 32 ms 47608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 47360 KB Output is correct
2 Incorrect 32 ms 47608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 47360 KB Output is correct
2 Incorrect 32 ms 47608 KB Output isn't correct
3 Halted 0 ms 0 KB -