답안 #532186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532186 2022-03-02T11:48:27 Z AdamGS 낙하산 고리들 (IOI12_rings) C++17
100 / 100
654 ms 64684 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=1e6+7;
pair<int,int>kraw[LIM];
int F[LIM], ile[LIM], deg[LIM], n, q, typ, ans;
vector<int>kand;
int F2[LIM][4], deg2[LIM][4], ok[4];
int fnd(int x) {
  if(F[x]==x) return x;
  return F[x]=fnd(F[x]);
}
int fnd2(int x, int y) {
  if(F2[x][y]==x) return x;
  return F2[x][y]=fnd2(F2[x][y], y);
}
void Init(int N) {
  n=N; ans=n;
  rep(i, n) {
    F[i]=i;
    ile[i]=1;
  }
}
void usun(int x) {
  kand.pb(x);
  rep(i, q) if(kraw[i].st==x || kraw[i].nd==x) kand.pb(kraw[i].st^kraw[i].nd^x);
  typ=2;
  ans=0;
  rep(j, 4) {
    rep(i, n) F2[i][j]=i;
    ok[j]=1;
    rep(i, q) if(kraw[i].st!=kand[j] && kraw[i].nd!=kand[j]) {
      if(fnd2(kraw[i].st, j)==fnd2(kraw[i].nd, j)) ok[j]=0;
      F2[fnd2(kraw[i].st, j)][j]=fnd2(kraw[i].nd, j);
      ++deg2[kraw[i].st][j];
      ++deg2[kraw[i].nd][j];
      if(deg2[kraw[i].st][j]==3 || deg2[kraw[i].nd][j]==3) ok[j]=0;
    }
    ans+=ok[j];
  }
}
void upd(int a, int b) {
  rep(i, 4) if(a!=kand[i] && b!=kand[i] && ok[i]) {
    if(fnd2(a, i)==fnd2(b, i)) {
      ok[i]=0;
      --ans;
      continue;
    }
    F2[fnd2(b, i)][i]=fnd2(a, i);
    ++deg2[a][i];
    ++deg2[b][i];
    if(deg2[a][i]==3 || deg2[b][i]==3) {
      ok[i]=0;
      --ans;
      continue;
    }
  }
}
void Link(int a, int b) {
  if(ans==0) return;
  kraw[q]={a, b};
  ++deg[a]; ++deg[b]; ++q;
  if(typ==2) {
    upd(a, b);
    return;
  }
  if(deg[a]<deg[b]) swap(a, b);
  if(deg[a]==3) {
    usun(a);
    return;
  }
  if(fnd(a)==fnd(b)) {
    if(typ==1) ans=0;
    else {
      typ=1;
      ans=ile[fnd(a)];
    }
    return;
  }
  ile[fnd(a)]+=ile[fnd(b)];
  F[fnd(b)]=fnd(a);
}
int CountCritical() {
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 17328 KB Output is correct
2 Correct 374 ms 51724 KB Output is correct
3 Correct 213 ms 55756 KB Output is correct
4 Correct 409 ms 33456 KB Output is correct
5 Correct 403 ms 33484 KB Output is correct
6 Correct 400 ms 32480 KB Output is correct
7 Correct 186 ms 55396 KB Output is correct
8 Correct 550 ms 60420 KB Output is correct
9 Correct 654 ms 64684 KB Output is correct
10 Correct 358 ms 32020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 972 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 2 ms 884 KB Output is correct
15 Correct 4 ms 1356 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1356 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 972 KB Output is correct
13 Correct 3 ms 972 KB Output is correct
14 Correct 2 ms 884 KB Output is correct
15 Correct 4 ms 1356 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1356 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
21 Correct 11 ms 1616 KB Output is correct
22 Correct 17 ms 2488 KB Output is correct
23 Correct 21 ms 3064 KB Output is correct
24 Correct 26 ms 5612 KB Output is correct
25 Correct 11 ms 5072 KB Output is correct
26 Correct 24 ms 5924 KB Output is correct
27 Correct 22 ms 3000 KB Output is correct
28 Correct 19 ms 5164 KB Output is correct
29 Correct 25 ms 5572 KB Output is correct
30 Correct 23 ms 3368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 160 ms 17328 KB Output is correct
12 Correct 374 ms 51724 KB Output is correct
13 Correct 213 ms 55756 KB Output is correct
14 Correct 409 ms 33456 KB Output is correct
15 Correct 403 ms 33484 KB Output is correct
16 Correct 400 ms 32480 KB Output is correct
17 Correct 186 ms 55396 KB Output is correct
18 Correct 550 ms 60420 KB Output is correct
19 Correct 654 ms 64684 KB Output is correct
20 Correct 358 ms 32020 KB Output is correct
21 Correct 2 ms 580 KB Output is correct
22 Correct 3 ms 972 KB Output is correct
23 Correct 3 ms 972 KB Output is correct
24 Correct 2 ms 884 KB Output is correct
25 Correct 4 ms 1356 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 3 ms 844 KB Output is correct
28 Correct 3 ms 1356 KB Output is correct
29 Correct 3 ms 588 KB Output is correct
30 Correct 3 ms 920 KB Output is correct
31 Correct 11 ms 1616 KB Output is correct
32 Correct 17 ms 2488 KB Output is correct
33 Correct 21 ms 3064 KB Output is correct
34 Correct 26 ms 5612 KB Output is correct
35 Correct 11 ms 5072 KB Output is correct
36 Correct 24 ms 5924 KB Output is correct
37 Correct 22 ms 3000 KB Output is correct
38 Correct 19 ms 5164 KB Output is correct
39 Correct 25 ms 5572 KB Output is correct
40 Correct 23 ms 3368 KB Output is correct
41 Correct 127 ms 13416 KB Output is correct
42 Correct 293 ms 48888 KB Output is correct
43 Correct 201 ms 45888 KB Output is correct
44 Correct 183 ms 48196 KB Output is correct
45 Correct 226 ms 53776 KB Output is correct
46 Correct 315 ms 28832 KB Output is correct
47 Correct 362 ms 29376 KB Output is correct
48 Correct 204 ms 51244 KB Output is correct
49 Correct 323 ms 30300 KB Output is correct
50 Correct 357 ms 29840 KB Output is correct
51 Correct 186 ms 40444 KB Output is correct
52 Correct 200 ms 40784 KB Output is correct
53 Correct 177 ms 50224 KB Output is correct
54 Correct 510 ms 53256 KB Output is correct
55 Correct 417 ms 57464 KB Output is correct