Submission #1098787

# Submission time Handle Problem Language Result Execution time Memory
1098787 2024-10-10T01:29:09 Z MtSaka Parachute rings (IOI12_rings) C++17
100 / 100
820 ms 115376 KB
#include"bits/stdc++.h"
#define overload(a,b,c,d,...) d
#define rep1(a) for(ll _=0;_<(ll)a;++_)
#define rep2(i,a) for(ll i=0;i<(ll)(a);++i)
#define rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)(a)-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using ld=long double;
using vi=vector<int>;
using vl=vector<ll>;
template<typename T,typename U>inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}

struct UnionFind{
    int n;
    vector<int>par;
    vector<int>deg;
    int ma,cycle,del;
    UnionFind(){}
    UnionFind(int n_):n(n_),par(n_+1,-1),deg(n_,0),ma(0),cycle(-1),del(-1){par[n]=0;}
    int root(int v){return (par[v]<0?v:par[v]=root(par[v]));}
    void merge(int u,int v){
        if(u==del||v==del||ma>2)return;
        chmax(ma,++deg[u]);
        chmax(ma,++deg[v]); 
        u=root(u),v=root(v);
        if(u==v){
            cycle=(cycle<0?u:n);
            return;
        }
        if(par[u]>par[v])swap(u,v);
        par[u]+=par[v];
        par[v]=u;
    }
    void set_del(int d){del=d;}
    int get()const{
        if(ma>2)return 0;
        if(cycle<0)return n;
        return par[cycle];
    }
};
UnionFind uf[5];
vector<vector<int>>g;
vector<pair<int,int>>edge;
bool f=false;
int n;
void Init(int N_) {
    n=N_;
    rep(i,5)uf[i]=UnionFind(n);
    g.resize(N_);
}
void Link(int A, int B) {
    edge.eb(A,B);
    g[A].eb(B);
    g[B].eb(A);
    if(!f){
        uf[0].merge(A,B);
        if(uf[0].ma>2){
            int id=0;
            rep(i,n)if(g[i].size()==3)id=i;
            uf[1].set_del(id);
            int idx=2;
            for(auto e:g[id])uf[idx++].set_del(e);
            f=true;
            for(auto [a,b]:edge)rep(j,4)uf[j+1].merge(a,b);
        }
    }
    else{
        rep(i,4)uf[i+1].merge(A,B);
    }
}

int CountCritical() {
    if(f){
        int ans=0;
        rep(i,4)if(uf[i+1].get()>0)ans++;
        return ans;
    }
    return abs(uf[0].get());
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 996 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 732 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 60096 KB Output is correct
2 Correct 516 ms 92336 KB Output is correct
3 Correct 556 ms 110220 KB Output is correct
4 Correct 605 ms 115320 KB Output is correct
5 Correct 627 ms 115376 KB Output is correct
6 Correct 567 ms 113328 KB Output is correct
7 Correct 463 ms 108828 KB Output is correct
8 Correct 758 ms 107952 KB Output is correct
9 Correct 820 ms 115372 KB Output is correct
10 Correct 400 ms 112432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 996 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 732 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 984 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 3 ms 1624 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 3 ms 1628 KB Output is correct
18 Correct 4 ms 2140 KB Output is correct
19 Correct 4 ms 1624 KB Output is correct
20 Correct 4 ms 1576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 996 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 732 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 984 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 3 ms 1624 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 3 ms 1628 KB Output is correct
18 Correct 4 ms 2140 KB Output is correct
19 Correct 4 ms 1624 KB Output is correct
20 Correct 4 ms 1576 KB Output is correct
21 Correct 12 ms 5076 KB Output is correct
22 Correct 26 ms 7892 KB Output is correct
23 Correct 21 ms 9788 KB Output is correct
24 Correct 25 ms 8904 KB Output is correct
25 Correct 9 ms 7260 KB Output is correct
26 Correct 26 ms 9872 KB Output is correct
27 Correct 26 ms 9940 KB Output is correct
28 Correct 30 ms 10436 KB Output is correct
29 Correct 18 ms 9176 KB Output is correct
30 Correct 28 ms 11460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 996 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 732 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 984 KB Output is correct
11 Correct 218 ms 60096 KB Output is correct
12 Correct 516 ms 92336 KB Output is correct
13 Correct 556 ms 110220 KB Output is correct
14 Correct 605 ms 115320 KB Output is correct
15 Correct 627 ms 115376 KB Output is correct
16 Correct 567 ms 113328 KB Output is correct
17 Correct 463 ms 108828 KB Output is correct
18 Correct 758 ms 107952 KB Output is correct
19 Correct 820 ms 115372 KB Output is correct
20 Correct 400 ms 112432 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 3 ms 1624 KB Output is correct
23 Correct 3 ms 1628 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 4 ms 1628 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 4 ms 2140 KB Output is correct
29 Correct 4 ms 1624 KB Output is correct
30 Correct 4 ms 1576 KB Output is correct
31 Correct 12 ms 5076 KB Output is correct
32 Correct 26 ms 7892 KB Output is correct
33 Correct 21 ms 9788 KB Output is correct
34 Correct 25 ms 8904 KB Output is correct
35 Correct 9 ms 7260 KB Output is correct
36 Correct 26 ms 9872 KB Output is correct
37 Correct 26 ms 9940 KB Output is correct
38 Correct 30 ms 10436 KB Output is correct
39 Correct 18 ms 9176 KB Output is correct
40 Correct 28 ms 11460 KB Output is correct
41 Correct 125 ms 45252 KB Output is correct
42 Correct 324 ms 79148 KB Output is correct
43 Correct 133 ms 65736 KB Output is correct
44 Correct 368 ms 105180 KB Output is correct
45 Correct 382 ms 98240 KB Output is correct
46 Correct 399 ms 95916 KB Output is correct
47 Correct 484 ms 97496 KB Output is correct
48 Correct 304 ms 88504 KB Output is correct
49 Correct 393 ms 104368 KB Output is correct
50 Correct 496 ms 103088 KB Output is correct
51 Correct 168 ms 59944 KB Output is correct
52 Correct 312 ms 85236 KB Output is correct
53 Correct 264 ms 88832 KB Output is correct
54 Correct 621 ms 93880 KB Output is correct
55 Correct 536 ms 102064 KB Output is correct