답안 #736216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736216 2023-05-05T10:25:25 Z becaido 낙하산 고리들 (IOI12_rings) C++17
0 / 100
2302 ms 159676 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1e6 + 5;

int n, mxdeg;
vector<int> adj[SIZE];

struct DS {
    int p, cnt[5], mxD;
    int cycle, csum;
    int to[SIZE], sz[SIZE], sum[SIZE], deg[SIZE], mxdeg[SIZE];
    void init() {
        memset(cnt, 0, sizeof(cnt));
        mxD = cycle = csum = 0;
        cnt[0] = n - (p != 0);
        iota(to + 1, to + n + 1, 1);
        fill(sz + 1, sz + n + 1, 1);
        fill(sum + 1, sum + n + 1, 0);
        fill(deg + 1, deg + n + 1, 0);
        fill(mxdeg + 1, mxdeg + n + 1, 0);
    }
    void build(int P = 0) {
        p = P;
        init();
        FOR (i, 1, n) for (int j : adj[i]) if (i < j) Merge(i, j);
    }
    int dsu(int x) {
        return x == to[x] ? x : (to[x] = dsu(to[x]));
    }
    void add(int x) {
        cnt[mxdeg[x] < 4 ? mxdeg[x] : 4]++;
        if (mxdeg[x] == 2 && sz[x] == sum[x]) cycle++, csum = sz[x];
        mxD = max(mxD, mxdeg[x]);
    }
    void del(int x) {
        cnt[mxdeg[x] < 4 ? mxdeg[x] : 4]--;
        if (mxdeg[x] == 2 && sz[x] == sum[x]) cycle--;
    }
    void Merge(int a, int b) {
        if (a == p || b == p) return;
        int da = dsu(a), db = dsu(b);
        if (da == db) del(da);
        else del(da), del(db);

        sum[da] -= deg[a] == 2;
        sum[db] -= deg[b] == 2;
        mxdeg[da] = max(mxdeg[da], ++deg[a]);
        mxdeg[db] = max(mxdeg[db], ++deg[b]);
        sum[da] += deg[a] == 2;
        sum[db] += deg[b] == 2;

        if (da == db) {add(da);return;}
        if (sz[da] < sz[db]) swap(da, db);
        to[db] = da;
        sz[da] += sz[db];
        sum[da] += sum[db];
        mxdeg[da] = max(mxdeg[da], mxdeg[db]);
        add(da);
    }
} ori, ds[4];

void Init(int N) {
    n = N;
    ori.build();
}

void Link(int a, int b) {
    a++, b++;
    if (a > b) swap(a, b);
    adj[a].pb(b);
    adj[b].pb(a);
    ori.Merge(a, b);
    int cur = ori.mxD;
    if (cur == mxdeg + 1) {
        if (cur == 4) {
            FOR (i, 1, n) if (adj[i].size() == 4) {
                ds[0].build(i);
                break;
            }
        }
        if (cur == 3) {
            FOR (i, 1, n) if (adj[i].size() == 3) {
                ds[0].build(i);
                int k = 0;
                for (int j : adj[i]) ds[++k].build(j);
                break;
            }
        }
    }
    mxdeg = cur;
    if (mxdeg == 4) ds[0].Merge(a, b);
    else if (mxdeg == 3) FOR (i, 0, 3) ds[i].Merge(a, b);
}

int CountCritical() {
    if (mxdeg <= 1) return n;
    if (mxdeg == 2) return ori.cycle == 0 ? n : ori.cycle == 1 ? ori.csum : 0;
    int ans = 0;
    FOR (i, 0, (mxdeg == 3 ? 3 : 0)) ans += ds[i].mxD <= 1 || (ds[i].mxD == 2 && ds[i].cycle == 0);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23800 KB Output is correct
2 Correct 16 ms 24600 KB Output is correct
3 Correct 15 ms 24612 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 16 ms 24020 KB Output is correct
6 Correct 15 ms 24152 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 15 ms 24016 KB Output is correct
9 Incorrect 19 ms 24724 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 57196 KB Output is correct
2 Correct 1300 ms 133020 KB Output is correct
3 Correct 991 ms 152396 KB Output is correct
4 Correct 1020 ms 77924 KB Output is correct
5 Correct 1030 ms 86264 KB Output is correct
6 Correct 1012 ms 85100 KB Output is correct
7 Correct 978 ms 159676 KB Output is correct
8 Incorrect 2302 ms 155964 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23800 KB Output is correct
2 Correct 16 ms 24600 KB Output is correct
3 Correct 15 ms 24612 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 16 ms 24020 KB Output is correct
6 Correct 15 ms 24152 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 15 ms 24016 KB Output is correct
9 Incorrect 19 ms 24724 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23800 KB Output is correct
2 Correct 16 ms 24600 KB Output is correct
3 Correct 15 ms 24612 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 16 ms 24020 KB Output is correct
6 Correct 15 ms 24152 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 15 ms 24016 KB Output is correct
9 Incorrect 19 ms 24724 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23800 KB Output is correct
2 Correct 16 ms 24600 KB Output is correct
3 Correct 15 ms 24612 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 16 ms 24020 KB Output is correct
6 Correct 15 ms 24152 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 15 ms 24016 KB Output is correct
9 Incorrect 19 ms 24724 KB Output isn't correct
10 Halted 0 ms 0 KB -