Submission #802273

# Submission time Handle Problem Language Result Execution time Memory
802273 2023-08-02T11:22:25 Z Dan4Life Parachute rings (IOI12_rings) C++17
100 / 100
1489 ms 122192 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
const int N = (int)1e6+9;
vector<int> v, adj[N];
array<int,2> edges[N];
int n, s=-1, T=1, ok=1, totE;

struct Dsu{
    bitset<N> bad;
    int deg[N], p[N], sz[N];
    int node, numBad, cycSz;
    void init(int N){
        node = -1; numBad=cycSz=0;
        for(int i = 0; i < N; i++)
            p[i]=i,sz[i]=1, bad[i]=deg[i]=0; 
    }
    int findSet(int i){ return i==p[i]?i:p[i]=findSet(p[i]); }
    void unionSet(int i, int j){
        if(i==node or j==node) return;
        deg[i]++, deg[j]++;
        int x = findSet(i), y = findSet(j);
        if(x==y){ 
            if(!bad[x]) numBad++, bad[x]=1;
            cycSz = sz[x]; return;
        }
        numBad-=bad[x]+bad[y];
        if(sz[x]<sz[y]) swap(x,y);
        p[y] = x; sz[x]+=sz[y];
        if(bad[x]||bad[y]||deg[i]>2||deg[j]>2)
            bad[x]=bad[y]=1, numBad++;
    }
} dsu[5];

void Init(int n_) { n = n_; for(int i=0;i<5;i++) dsu[i].init(n); }

void Link(int a, int b) {
    edges[totE++]={a,b}; adj[a].pb(b); adj[b].pb(a);
    for(int i=0;i<T;i++) dsu[i].unionSet(a,b);
    if(dsu[0].deg[a]==4 and sz(v)<=1) v.pb(a);
    if(dsu[0].deg[b]==4 and sz(v)<=1) v.pb(b);
    if(dsu[0].deg[a]==3 and s==-1) s=a;
    if(dsu[0].deg[b]==3 and s==-1) s=b;
}

int CountCritical(){
    if(sz(v)>=2 or dsu[0].numBad>=2) return 0;
    if(!dsu[0].numBad) return n;
    if(sz(v)==1){
        if(ok){
            dsu[T++].node = v[0]; ok=0;
            for(int i = 0; i < totE; i++)
                dsu[1].unionSet(edges[i][0],edges[i][1]);
        }
        return !dsu[1].numBad;
    }
    if(s==-1) return dsu[0].cycSz;
    if(ok){
        dsu[T++].node=s; ok = 0;
        for(auto u : adj[s]) dsu[T++].node=u;
        for(int j = 1; j < T; j++)
          for(int i = 0; i < totE; i++)
              dsu[j].unionSet(edges[i][0],edges[i][1]);
    }
    int ans=0;for(int i=1;i<T;i++)ans+=!dsu[i].numBad; return ans;
}

Compilation message

rings.cpp: In member function 'void Dsu::init(int)':
rings.cpp:17:42: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   17 |             p[i]=i,sz[i]=1, bad[i]=deg[i]=0;
      |                                    ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24532 KB Output is correct
2 Correct 13 ms 24928 KB Output is correct
3 Correct 14 ms 25044 KB Output is correct
4 Correct 13 ms 24536 KB Output is correct
5 Correct 14 ms 24788 KB Output is correct
6 Correct 14 ms 25044 KB Output is correct
7 Correct 13 ms 24804 KB Output is correct
8 Correct 13 ms 24916 KB Output is correct
9 Correct 18 ms 25004 KB Output is correct
10 Correct 14 ms 25044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 75304 KB Output is correct
2 Correct 732 ms 102708 KB Output is correct
3 Correct 850 ms 117820 KB Output is correct
4 Correct 872 ms 122192 KB Output is correct
5 Correct 851 ms 122172 KB Output is correct
6 Correct 972 ms 120484 KB Output is correct
7 Correct 798 ms 116884 KB Output is correct
8 Correct 993 ms 116056 KB Output is correct
9 Correct 1120 ms 122072 KB Output is correct
10 Correct 595 ms 120096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24532 KB Output is correct
2 Correct 13 ms 24928 KB Output is correct
3 Correct 14 ms 25044 KB Output is correct
4 Correct 13 ms 24536 KB Output is correct
5 Correct 14 ms 24788 KB Output is correct
6 Correct 14 ms 25044 KB Output is correct
7 Correct 13 ms 24804 KB Output is correct
8 Correct 13 ms 24916 KB Output is correct
9 Correct 18 ms 25004 KB Output is correct
10 Correct 14 ms 25044 KB Output is correct
11 Correct 13 ms 25044 KB Output is correct
12 Correct 20 ms 25428 KB Output is correct
13 Correct 17 ms 25452 KB Output is correct
14 Correct 15 ms 25292 KB Output is correct
15 Correct 15 ms 25944 KB Output is correct
16 Correct 17 ms 25428 KB Output is correct
17 Correct 18 ms 25556 KB Output is correct
18 Correct 20 ms 26148 KB Output is correct
19 Correct 19 ms 25504 KB Output is correct
20 Correct 17 ms 25428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24532 KB Output is correct
2 Correct 13 ms 24928 KB Output is correct
3 Correct 14 ms 25044 KB Output is correct
4 Correct 13 ms 24536 KB Output is correct
5 Correct 14 ms 24788 KB Output is correct
6 Correct 14 ms 25044 KB Output is correct
7 Correct 13 ms 24804 KB Output is correct
8 Correct 13 ms 24916 KB Output is correct
9 Correct 18 ms 25004 KB Output is correct
10 Correct 14 ms 25044 KB Output is correct
11 Correct 13 ms 25044 KB Output is correct
12 Correct 20 ms 25428 KB Output is correct
13 Correct 17 ms 25452 KB Output is correct
14 Correct 15 ms 25292 KB Output is correct
15 Correct 15 ms 25944 KB Output is correct
16 Correct 17 ms 25428 KB Output is correct
17 Correct 18 ms 25556 KB Output is correct
18 Correct 20 ms 26148 KB Output is correct
19 Correct 19 ms 25504 KB Output is correct
20 Correct 17 ms 25428 KB Output is correct
21 Correct 29 ms 28744 KB Output is correct
22 Correct 35 ms 31188 KB Output is correct
23 Correct 40 ms 32892 KB Output is correct
24 Correct 42 ms 31944 KB Output is correct
25 Correct 25 ms 30660 KB Output is correct
26 Correct 51 ms 32764 KB Output is correct
27 Correct 45 ms 32844 KB Output is correct
28 Correct 61 ms 33192 KB Output is correct
29 Correct 66 ms 32348 KB Output is correct
30 Correct 59 ms 34188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24532 KB Output is correct
2 Correct 13 ms 24928 KB Output is correct
3 Correct 14 ms 25044 KB Output is correct
4 Correct 13 ms 24536 KB Output is correct
5 Correct 14 ms 24788 KB Output is correct
6 Correct 14 ms 25044 KB Output is correct
7 Correct 13 ms 24804 KB Output is correct
8 Correct 13 ms 24916 KB Output is correct
9 Correct 18 ms 25004 KB Output is correct
10 Correct 14 ms 25044 KB Output is correct
11 Correct 267 ms 75304 KB Output is correct
12 Correct 732 ms 102708 KB Output is correct
13 Correct 850 ms 117820 KB Output is correct
14 Correct 872 ms 122192 KB Output is correct
15 Correct 851 ms 122172 KB Output is correct
16 Correct 972 ms 120484 KB Output is correct
17 Correct 798 ms 116884 KB Output is correct
18 Correct 993 ms 116056 KB Output is correct
19 Correct 1120 ms 122072 KB Output is correct
20 Correct 595 ms 120096 KB Output is correct
21 Correct 13 ms 25044 KB Output is correct
22 Correct 20 ms 25428 KB Output is correct
23 Correct 17 ms 25452 KB Output is correct
24 Correct 15 ms 25292 KB Output is correct
25 Correct 15 ms 25944 KB Output is correct
26 Correct 17 ms 25428 KB Output is correct
27 Correct 18 ms 25556 KB Output is correct
28 Correct 20 ms 26148 KB Output is correct
29 Correct 19 ms 25504 KB Output is correct
30 Correct 17 ms 25428 KB Output is correct
31 Correct 29 ms 28744 KB Output is correct
32 Correct 35 ms 31188 KB Output is correct
33 Correct 40 ms 32892 KB Output is correct
34 Correct 42 ms 31944 KB Output is correct
35 Correct 25 ms 30660 KB Output is correct
36 Correct 51 ms 32764 KB Output is correct
37 Correct 45 ms 32844 KB Output is correct
38 Correct 61 ms 33192 KB Output is correct
39 Correct 66 ms 32348 KB Output is correct
40 Correct 59 ms 34188 KB Output is correct
41 Correct 174 ms 63968 KB Output is correct
42 Correct 615 ms 92920 KB Output is correct
43 Correct 336 ms 82848 KB Output is correct
44 Correct 1078 ms 113620 KB Output is correct
45 Correct 1099 ms 108532 KB Output is correct
46 Correct 737 ms 105232 KB Output is correct
47 Correct 806 ms 106808 KB Output is correct
48 Correct 639 ms 102176 KB Output is correct
49 Correct 613 ms 114268 KB Output is correct
50 Correct 732 ms 113064 KB Output is correct
51 Correct 388 ms 77140 KB Output is correct
52 Correct 966 ms 96164 KB Output is correct
53 Correct 722 ms 102840 KB Output is correct
54 Correct 1203 ms 103588 KB Output is correct
55 Correct 1489 ms 110756 KB Output is correct