답안 #596063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596063 2022-07-14T10:05:12 Z Mamedov 낙하산 고리들 (IOI12_rings) C++17
100 / 100
593 ms 53040 KB
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct DSU {
  int components;
  vector<int>par;
  DSU(){}
  DSU(int n) {
    par.assign(n, -1);
    components = n;
  }
  void init(int n) {
    par.assign(n, -1);
    components = n;
  }
  int Find(int u) {
    if (par[u] < 0) return u;
    else return par[u] = Find(par[u]);
  }
  bool Union(int u, int v) {
    u = Find(u);
    v = Find(v);
    if (u != v) {
      if (par[u] > par[v]) {
        swap(u, v);
      }
      par[u] += par[v];
      par[v] = u;
      --components;
      return true;
    } else {
      return false;
    }
  }
};

int N, critical, cycle;
DSU dsu[4];
bool isCritical[4];
int root[4];
vpii edges;
vi deg[4];

void Init(int N_) {
  N = N_;
  critical = N;
  cycle = 0;
  for (int i = 0; i < 4; ++i) {
    dsu[i].init(N);
    deg[i].assign(N, 0);
    root[i] = -1;
  }
}

void Link(int A, int B) {
  if (!critical) return;
  if (root[0] == -1) {
    edges.eb(mpr(A, B));
    deg[0][A]++;
    deg[0][B]++;
    if (deg[0][A] == 3) {
      root[0] = A;
    } else if (deg[0][B] == 3) {
      root[0] = B;
    }
    if (root[0] != -1) {
      int id = 0;
      for (pii e : edges) {
        if (e.f == root[0] || e.s == root[0]) {
          root[++id] = e.f + e.s - root[0];
        }
      }
      dsu[0].init(N);
      deg[0].assign(N, 0);
      critical = 4;
      for (int i = 0; i < 4; ++i) {
        isCritical[i] = true;
        for (pii e : edges) {
          if (e.f != root[i] && e.s != root[i]) {
            deg[i][e.f]++;
            deg[i][e.s]++;
            if (!dsu[i].Union(e.f, e.s) || deg[i][e.f] >= 3 || deg[i][e.s] >= 3) {
              isCritical[i] = false;
              --critical;
              break;
            }
          }
        }
      }
    } else {
      if (!dsu[0].Union(A, B)) {
        ++cycle;
        if (cycle == 1) {
          critical = -dsu[0].par[dsu[0].Find(A)];
        } else {
          critical = 0;
        }
      }
    }
  } else {
    for (int i = 0; i < 4; ++i) {
      if (isCritical[i] && root[i] != A && root[i] != B) {
        deg[i][A]++;
        deg[i][B]++;
        if (!dsu[i].Union(A, B) || deg[i][A] >= 3 || deg[i][B] >= 3) {
          isCritical[i] = false;
          --critical;
        }
      }
    }
  }
}

int CountCritical() {
  return critical;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 20780 KB Output is correct
2 Correct 341 ms 30660 KB Output is correct
3 Correct 189 ms 33300 KB Output is correct
4 Correct 391 ms 41268 KB Output is correct
5 Correct 363 ms 53040 KB Output is correct
6 Correct 348 ms 52124 KB Output is correct
7 Correct 214 ms 43908 KB Output is correct
8 Correct 593 ms 47316 KB Output is correct
9 Correct 565 ms 51608 KB Output is correct
10 Correct 286 ms 51844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 980 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 2 ms 784 KB Output is correct
18 Correct 3 ms 1108 KB Output is correct
19 Correct 3 ms 908 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 980 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 2 ms 784 KB Output is correct
18 Correct 3 ms 1108 KB Output is correct
19 Correct 3 ms 908 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
21 Correct 11 ms 2776 KB Output is correct
22 Correct 18 ms 4312 KB Output is correct
23 Correct 23 ms 5080 KB Output is correct
24 Correct 29 ms 4044 KB Output is correct
25 Correct 13 ms 3756 KB Output is correct
26 Correct 21 ms 4308 KB Output is correct
27 Correct 21 ms 5204 KB Output is correct
28 Correct 17 ms 4136 KB Output is correct
29 Correct 19 ms 4188 KB Output is correct
30 Correct 24 ms 5608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 146 ms 20780 KB Output is correct
12 Correct 341 ms 30660 KB Output is correct
13 Correct 189 ms 33300 KB Output is correct
14 Correct 391 ms 41268 KB Output is correct
15 Correct 363 ms 53040 KB Output is correct
16 Correct 348 ms 52124 KB Output is correct
17 Correct 214 ms 43908 KB Output is correct
18 Correct 593 ms 47316 KB Output is correct
19 Correct 565 ms 51608 KB Output is correct
20 Correct 286 ms 51844 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 3 ms 980 KB Output is correct
23 Correct 3 ms 852 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 3 ms 980 KB Output is correct
26 Correct 3 ms 980 KB Output is correct
27 Correct 2 ms 784 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 3 ms 908 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 11 ms 2776 KB Output is correct
32 Correct 18 ms 4312 KB Output is correct
33 Correct 23 ms 5080 KB Output is correct
34 Correct 29 ms 4044 KB Output is correct
35 Correct 13 ms 3756 KB Output is correct
36 Correct 21 ms 4308 KB Output is correct
37 Correct 21 ms 5204 KB Output is correct
38 Correct 17 ms 4136 KB Output is correct
39 Correct 19 ms 4188 KB Output is correct
40 Correct 24 ms 5608 KB Output is correct
41 Correct 119 ms 23364 KB Output is correct
42 Correct 315 ms 38300 KB Output is correct
43 Correct 184 ms 34368 KB Output is correct
44 Correct 203 ms 41560 KB Output is correct
45 Correct 236 ms 41276 KB Output is correct
46 Correct 302 ms 44844 KB Output is correct
47 Correct 305 ms 45840 KB Output is correct
48 Correct 232 ms 39684 KB Output is correct
49 Correct 277 ms 50020 KB Output is correct
50 Correct 291 ms 49272 KB Output is correct
51 Correct 172 ms 30128 KB Output is correct
52 Correct 192 ms 34148 KB Output is correct
53 Correct 213 ms 38908 KB Output is correct
54 Correct 408 ms 40816 KB Output is correct
55 Correct 351 ms 40252 KB Output is correct