답안 #802594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802594 2023-08-02T12:51:01 Z Dan4Life 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1228 ms 80780 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;
array<int,2> adj[N*2];
int n, s=-1, T=1, ok=1, totE=1, adjH[N];
 
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;
        }
        if(sz[x]<sz[y]) swap(x,y);
        p[y] = x; sz[x]+=sz[y];
        numBad-=bad[x]+bad[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){
    adj[totE]={b,adjH[a]}; adjH[a]=totE; totE++;
    adj[totE]={a,adjH[b]}; adjH[b]=totE; totE++;
    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 < n; i++)
                for(int j = adjH[i]; j; j=adj[j][1])
                    if(i<adj[j][0]) dsu[1].unionSet(i,adj[j][0]);
        }
        return !dsu[1].numBad;
    }
    if(s==-1) return dsu[0].cycSz;
    if(ok){
        dsu[T++].node=s; ok = 0;
        for(int j = adjH[s]; j; j=adj[j][1]) dsu[T++].node=adj[j][0];
        for(int i = 0; i < n; i++)
            for(int j = adjH[i]; j; j=adj[j][1])
                if(i<adj[j][0]) for(int k = 1; k < T; k++) 
                    dsu[k].unionSet(i,adj[j][0]);
    }
    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;
      |                                    ~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 1364 KB Output is correct
3 Correct 3 ms 1492 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1364 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 3 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 41664 KB Output is correct
2 Correct 438 ms 63624 KB Output is correct
3 Correct 380 ms 79740 KB Output is correct
4 Correct 398 ms 80780 KB Output is correct
5 Correct 370 ms 80668 KB Output is correct
6 Correct 463 ms 79824 KB Output is correct
7 Correct 502 ms 79112 KB Output is correct
8 Correct 1046 ms 75536 KB Output is correct
9 Correct 1228 ms 80320 KB Output is correct
10 Correct 423 ms 79364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 1364 KB Output is correct
3 Correct 3 ms 1492 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1364 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 3 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 5 ms 1876 KB Output is correct
13 Correct 3 ms 1936 KB Output is correct
14 Correct 2 ms 1776 KB Output is correct
15 Correct 4 ms 2388 KB Output is correct
16 Correct 4 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 2516 KB Output is correct
19 Correct 3 ms 1876 KB Output is correct
20 Correct 3 ms 1940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 1364 KB Output is correct
3 Correct 3 ms 1492 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1364 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 3 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 5 ms 1876 KB Output is correct
13 Correct 3 ms 1936 KB Output is correct
14 Correct 2 ms 1776 KB Output is correct
15 Correct 4 ms 2388 KB Output is correct
16 Correct 4 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 2516 KB Output is correct
19 Correct 3 ms 1876 KB Output is correct
20 Correct 3 ms 1940 KB Output is correct
21 Correct 11 ms 5188 KB Output is correct
22 Correct 20 ms 7564 KB Output is correct
23 Correct 21 ms 9036 KB Output is correct
24 Correct 22 ms 8272 KB Output is correct
25 Correct 18 ms 7736 KB Output is correct
26 Correct 35 ms 8616 KB Output is correct
27 Correct 21 ms 8188 KB Output is correct
28 Correct 30 ms 8444 KB Output is correct
29 Correct 35 ms 8508 KB Output is correct
30 Correct 31 ms 9196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 1364 KB Output is correct
3 Correct 3 ms 1492 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1364 KB Output is correct
8 Correct 2 ms 1364 KB Output is correct
9 Correct 3 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 173 ms 41664 KB Output is correct
12 Correct 438 ms 63624 KB Output is correct
13 Correct 380 ms 79740 KB Output is correct
14 Correct 398 ms 80780 KB Output is correct
15 Correct 370 ms 80668 KB Output is correct
16 Correct 463 ms 79824 KB Output is correct
17 Correct 502 ms 79112 KB Output is correct
18 Correct 1046 ms 75536 KB Output is correct
19 Correct 1228 ms 80320 KB Output is correct
20 Correct 423 ms 79364 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 5 ms 1876 KB Output is correct
23 Correct 3 ms 1936 KB Output is correct
24 Correct 2 ms 1776 KB Output is correct
25 Correct 4 ms 2388 KB Output is correct
26 Correct 4 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 3 ms 2516 KB Output is correct
29 Correct 3 ms 1876 KB Output is correct
30 Correct 3 ms 1940 KB Output is correct
31 Correct 11 ms 5188 KB Output is correct
32 Correct 20 ms 7564 KB Output is correct
33 Correct 21 ms 9036 KB Output is correct
34 Correct 22 ms 8272 KB Output is correct
35 Correct 18 ms 7736 KB Output is correct
36 Correct 35 ms 8616 KB Output is correct
37 Correct 21 ms 8188 KB Output is correct
38 Correct 30 ms 8444 KB Output is correct
39 Correct 35 ms 8508 KB Output is correct
40 Correct 31 ms 9196 KB Output is correct
41 Correct 127 ms 38752 KB Output is correct
42 Correct 563 ms 63584 KB Output is correct
43 Correct 248 ms 62780 KB Output is correct
44 Correct 846 ms 74000 KB Output is correct
45 Correct 725 ms 74200 KB Output is correct
46 Correct 412 ms 67048 KB Output is correct
47 Correct 513 ms 68412 KB Output is correct
48 Correct 516 ms 71332 KB Output is correct
49 Correct 385 ms 78068 KB Output is correct
50 Correct 377 ms 76872 KB Output is correct
51 Correct 323 ms 54980 KB Output is correct
52 Correct 675 ms 59892 KB Output is correct
53 Correct 595 ms 71308 KB Output is correct
54 Correct 1057 ms 65616 KB Output is correct
55 Correct 1097 ms 71148 KB Output is correct