Submission #120732

# Submission time Handle Problem Language Result Execution time Memory
120732 2019-06-25T11:08:50 Z MAMBA Parachute rings (IOI12_rings) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back

constexpr int MAXN = 1e6 + 10;

struct dsu {
  int par[MAXN], sz[MAXN];
  dsu() {
    iota(par, par + MAXN, 0);
    fill(sz, sz + MAXN, 1);
  }
  int getPar(int v) { return par[v] == v ? v : par[v] = getPar(par[v]); }
  int merge(int u, int v) {
    v = getPar(v), u = getPar(u);
    if (v == u) return sz[v];
    par[v] = u;
    sz[u] += sz[v];
    return -1;
  }
} ds[5];

int N, tmp, deg[5][MAXN];
vector<int> adj[MAXN];
bool flag, can[5];

void Init(int N_) {
  N = N_;
  tmp = 0;
  flag = false;
  memset(can, true, sizeof(can));
  memset(deg, 0, sizeof(deg));
  rep(i, 0, 5) ds[i] = dsu();
  rep(i, 0, N) adj[i].clear();
}

int bad[5];

inline void Link(int A, int B, int id) {
  if (bad[id] == A || bad[id] == B) return;
  deg[id][A]++, deg[id][B]++;
  if (deg[id][A] == 3 || deg[id][B] == 3) can[id] = false;
  if (ds[id].merge(A, B) == -1) can[id] = false;
}

inline void build(int v) {
  flag = true;
  bad[1] = v;
  rep(i, 0, 3) bad[2 + i] = adj[v][i];
  rep(i, 0, N) for (auto e : adj[i]) if (e > i) rep(z, 1, 5) Link(i, e, z);
}

void Link(int A, int B) {
  adj[A].pb(B);
  adj[B].pb(A);
  if (!flag && adj[A].size() == 3) 
    build(A);
  if (!flag && adj[B].size() == 3) {
    build(B);
  if (!flag) {
    int me = ds[0].merge(A, B);
    if (~me) {
      if (!tmp)
        tmp = me;
      else
        tmp = -1;
    }
  } else
    rep(i, 1, 5) Link(A, B, i);
}

int CountCritical() {
  if (!flag) {
    if (!tmp) return N;
    if (~tmp) return tmp;
    return 0;
  }
  int res = 0;
  rep(i, 1, 5) res += can[i];
  return res;
}

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:75:21: error: a function-definition is not allowed here before '{' token
 int CountCritical() {
                     ^
rings.cpp:84:1: error: expected '}' at end of input
 }
 ^