답안 #350260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
350260 2021-01-19T04:38:46 Z casperwang 낙하산 고리들 (IOI12_rings) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
 
int N, cnt;
vector <int> dsu; // DSU
vector <int> sze; // SIZE of DSU
vector <int> deg; // degree
vector < vector<int> > path;
vector <int> nowCritical; // now answer
 
void Init(int n) {
  N = n;
  nowCritical.clear();
  dsu.clear(), dsu.resize(N);
  sze.clear(), sze.resize(N);
  deg.clear(), deg.resize(N);
  path.clear(), path.resize(N);
  for (int i = 0; i < N; i++) {
    dsu[i] = i;
    nowCritical.pb(i);
  }
}
 
int fnd(int a) {
  return dsu[a] == a ? dsu[a] : dsu[a] = fnd(dsu[a]);
}
 
inline void Union(int a, int b) {
  a = fnd(a), b = fnd(b);
  if (sze[a] > sze[b]) {
    sze[a] += sze[b];
    dsu[b] = a;
  } else {
    sze[b] += sze[a];
    dsu[a] = b;
  }
}
 
inline void Only(int v) {
  bool flag = 0;
  for (int i : nowCritical)
    if (i == v) flag = 1;
  nowCritical.clear();
  if (flag) nowCritical.pb(v);
  return;
}
 
void Left(int v) {
  vector <int> tmp;
  for (int j : nowCritical) {
    if (int i = 0; i < 3; i++)
      if (j == path[v][i]) tmp.pb(j);
    if (j == v) tmp.pb(v);
  }
  nowCritical = tmp;
  return;
}
 
bool del(int id, int a, int b) {
  if (id == a || id == b) return 1;
  vector <int> vis(N);
  queue <int> nxt;
  nxt.push(a), vis[a] = 1;
  while (nxt.size() && !vis[b]) {
    int now = nxt.front();
    nxt.pop();
    for (int i : path[now]) {
      if (vis[i] || i == id) continue;
      vis[i] = 1, nxt.push(i);
    }
  }
  return !vis[b];
}
 
void BFS(int s, int t) {
  vector <int> tmp;
  for (int i : nowCritical)
    if (fnd(i) == fnd(s) && del(i, s, t))
      tmp.pb(i);
  nowCritical = tmp;
  return;
}
 
void Link(int a, int b) {
  if (!nowCritical.size()) return;
  deg[a]++;
  if (deg[a] >= 4) Only(a);
  deg[b]++;
  if (deg[b] >= 4) Only(b);
  if (fnd(a) != fnd(b)) {
    Union(a, b);
  } else if (nowCritical.size()) {
    cnt++;
    assert(cnt < 20);
    BFS(a, b);
  }
  path[a].pb(b);
  if (deg[a] == 3) Left(a);
  path[b].pb(a);
  if (deg[b] == 3) Left(b);
  return;
}
 
int CountCritical() {
  return nowCritical.size();
}

Compilation message

rings.cpp: In function 'void Left(int)':
rings.cpp:57:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   57 |     if (int i = 0; i < 3; i++)
      |         ^~~
rings.cpp:57:25: error: expected ')' before ';' token
   57 |     if (int i = 0; i < 3; i++)
      |        ~                ^
      |                         )
rings.cpp:57:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   57 |     if (int i = 0; i < 3; i++)
      |     ^~
rings.cpp:57:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   57 |     if (int i = 0; i < 3; i++)
      |                           ^
rings.cpp:57:27: error: 'i' was not declared in this scope