Submission #736114

# Submission time Handle Problem Language Result Execution time Memory
736114 2023-05-05T08:37:41 Z becaido Parachute rings (IOI12_rings) C++17
0 / 100
2365 ms 161564 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 && sum[x] == 2 * sz[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 && sum[x] == 2 * sz[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]++, sum[db]++;
        mxdeg[da] = max(mxdeg[da], ++deg[a]);
        mxdeg[db] = max(mxdeg[db], ++deg[b]);
 
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;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 24544 KB Output is correct
3 Correct 17 ms 24604 KB Output is correct
4 Correct 15 ms 23892 KB Output is correct
5 Correct 15 ms 24020 KB Output is correct
6 Correct 17 ms 24104 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 16 ms 24020 KB Output is correct
9 Incorrect 19 ms 24600 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 438 ms 53904 KB Output is correct
2 Correct 1370 ms 129280 KB Output is correct
3 Correct 1111 ms 161564 KB Output is correct
4 Correct 1151 ms 87896 KB Output is correct
5 Correct 1212 ms 88000 KB Output is correct
6 Correct 1124 ms 86632 KB Output is correct
7 Correct 1038 ms 160648 KB Output is correct
8 Incorrect 2365 ms 157352 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 24544 KB Output is correct
3 Correct 17 ms 24604 KB Output is correct
4 Correct 15 ms 23892 KB Output is correct
5 Correct 15 ms 24020 KB Output is correct
6 Correct 17 ms 24104 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 16 ms 24020 KB Output is correct
9 Incorrect 19 ms 24600 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 24544 KB Output is correct
3 Correct 17 ms 24604 KB Output is correct
4 Correct 15 ms 23892 KB Output is correct
5 Correct 15 ms 24020 KB Output is correct
6 Correct 17 ms 24104 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 16 ms 24020 KB Output is correct
9 Incorrect 19 ms 24600 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 17 ms 24544 KB Output is correct
3 Correct 17 ms 24604 KB Output is correct
4 Correct 15 ms 23892 KB Output is correct
5 Correct 15 ms 24020 KB Output is correct
6 Correct 17 ms 24104 KB Output is correct
7 Correct 15 ms 24404 KB Output is correct
8 Correct 16 ms 24020 KB Output is correct
9 Incorrect 19 ms 24600 KB Output isn't correct
10 Halted 0 ms 0 KB -