답안 #658040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658040 2022-11-12T02:00:33 Z jiahng 낙하산 고리들 (IOI12_rings) C++14
0 / 100
51 ms 77920 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N;

unordered_set <int> st[maxn];
int d[maxn],sz[maxn],edges[maxn];
int maxD;
int E = 0;
int p[maxn];
vi adj[maxn];
unordered_set <int> cycles;
int ncomp;
int fl(int x){
    if (p[x] == x) return x;
    return p[x] = fl(p[x]);
}

int pr[5][maxn];
int edgesr[5][maxn], szr[5][maxn];
vpi all_edges;
unordered_set <int> cyclesr[maxn];
vi pos;
int flr(int i, int x){
    if (pr[i][x] == x) return x;
    return pr[i][x] = flr(i, pr[i][x]);
}
void Init(int N_) {
    N = N_;
    ncomp = N;
    maxD = 0;
    FOR(i,0,N-1) p[i] = i, sz[i] = 1;
    FOR(i,0,3) FOR(j,0,N-1) pr[i][j] = j,szr[i][j] = 1;
}
void add(int A, int B){
    edges[fl(B)]++;
    if (fl(A) != fl(B)){
        int pA = fl(A), pB = fl(B);
        sz[pB] += sz[pA];
        edges[pB] += edges[pA];
        if (cycles.find(pA) != cycles.end()) cycles.erase(pA);
        p[pA] = pB;
    }
    if (edges[fl(B)] >= sz[fl(B)]) cycles.insert(fl(B));
}
void addr(int i, int A, int B){
    edgesr[i][flr(i,B)]++;
    if (flr(i, A) != flr(i,B)){
        int pA = flr(i,A), pB = flr(i,B);
        szr[i][pB] += szr[i][pA];
        edgesr[i][pB] += edgesr[i][pA];
        if (cyclesr[i].find(pA) != cyclesr[i].end()) cyclesr[i].erase(pA);
        pr[i][pA] = pB;
    }
    if (edgesr[i][flr(i,B)] >= szr[i][flr(i,B)]) cyclesr[i].insert(flr(i,B));
}
int deg1[maxn];
void Link(int A, int B) {
    st[d[A]].erase(A); st[d[B]].erase(B);
    d[A]++; d[B]++;

    adj[A].pb(B); adj[B].pb(A);

    if (pos.empty() && (d[A] == 3 || d[B] == 3)){
        if (d[A] == 3){
            aFOR(i, adj[A]) pos.pb(i);
            pos.pb(A);
        }else if (d[B] == 3){
            pos.pb(B); aFOR(i, adj[B]) pos.pb(i);
        }
        FOR(i,0,pos.size()-1){
            aFOR(j, all_edges) if (j.f != pos[i] && j.s != pos[i]) addr(i,j.f,j.s);
        }
    }

    all_edges.pb(pi(A,B));
    st[d[A]].insert(A); st[d[B]].insert(B);
    maxD = max({maxD, d[A], d[B]});


    E++;
    add(A,B);
    if (edges[fl(B)] >= sz[fl(B)]) cycles.insert(fl(B));
    FOR(i,0,pos.size()-1) if (A != pos[i] && B != pos[i]) addr(i,A,B);
}

int CountCritical() {
    if (maxD >= 4){
        if (st[4].size() == 1) return 1;
        else return 0;
    }else if (maxD <= 1) return N;
    else if (maxD == 3){
        if (st[3].size() > 4) return 0;
       
        int ans = 0;
        //cout << pos[0] << ' ';
        /*
        FOR(i,0,N-1) cout << flr(1,i) << ' ';
        cout << '\n';
        FOR(i,0,N-1) cout << szr[1][flr(1,i)] << ' ';
        cout << '\n';
        FOR(i,0,N-1) cout << edgesr[1][flr(1,i)] << ' ';
        cout << '\n';
        cout << cyclesr[1].size() << ' ';
        cout << '\n';
        */
        aFOR(i, pos){
            bool no = 0;
            aFOR(j, st[3]) if (i != j && find(all(adj[i]), j) == adj[i].end()) no = 1;
            if (no) continue;
            if (cyclesr[i].empty()){
                ans++;
            }
        }
        return ans;
    }else{
        if (cycles.size() == 0) return N;
        else if (cycles.size() == 1) return sz[fl(*cycles.begin())];
        else return 0;
    }


    return N;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 26964 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Incorrect 19 ms 27804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 77920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 26964 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Incorrect 19 ms 27804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 26964 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Incorrect 19 ms 27804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 26964 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Incorrect 19 ms 27804 KB Output isn't correct
4 Halted 0 ms 0 KB -