Submission #350245

# Submission time Handle Problem Language Result Execution time Memory
350245 2021-01-19T04:34:44 Z casperwang Parachute rings (IOI12_rings) C++14
38 / 100
4000 ms 78672 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;
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]);
}
 
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;
  }
}
 
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 i = 0; i < 3; i++)
    for (int j : nowCritical)
      if (j == path[v][i]) tmp.pb(j);
  for (int j : nowCritical)
    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()) {
    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();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 41 ms 620 KB Output is correct
6 Correct 173 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 36964 KB Output is correct
2 Correct 911 ms 56828 KB Output is correct
3 Correct 287 ms 39908 KB Output is correct
4 Correct 1525 ms 78672 KB Output is correct
5 Execution timed out 4043 ms 78592 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 41 ms 620 KB Output is correct
6 Correct 173 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 8 ms 1132 KB Output is correct
13 Correct 7 ms 1132 KB Output is correct
14 Correct 9 ms 1004 KB Output is correct
15 Correct 18 ms 1388 KB Output is correct
16 Correct 7 ms 1132 KB Output is correct
17 Correct 3 ms 876 KB Output is correct
18 Correct 5 ms 1260 KB Output is correct
19 Correct 8 ms 1132 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 41 ms 620 KB Output is correct
6 Correct 173 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 8 ms 1132 KB Output is correct
13 Correct 7 ms 1132 KB Output is correct
14 Correct 9 ms 1004 KB Output is correct
15 Correct 18 ms 1388 KB Output is correct
16 Correct 7 ms 1132 KB Output is correct
17 Correct 3 ms 876 KB Output is correct
18 Correct 5 ms 1260 KB Output is correct
19 Correct 8 ms 1132 KB Output is correct
20 Correct 5 ms 1132 KB Output is correct
21 Correct 28 ms 3440 KB Output is correct
22 Correct 37 ms 5612 KB Output is correct
23 Correct 47 ms 7148 KB Output is correct
24 Correct 466 ms 7168 KB Output is correct
25 Correct 103 ms 5096 KB Output is correct
26 Correct 48 ms 7020 KB Output is correct
27 Correct 54 ms 7204 KB Output is correct
28 Correct 31 ms 5284 KB Output is correct
29 Correct 33 ms 5228 KB Output is correct
30 Execution timed out 4064 ms 9196 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 41 ms 620 KB Output is correct
6 Correct 173 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 464 ms 36964 KB Output is correct
12 Correct 911 ms 56828 KB Output is correct
13 Correct 287 ms 39908 KB Output is correct
14 Correct 1525 ms 78672 KB Output is correct
15 Execution timed out 4043 ms 78592 KB Time limit exceeded
16 Halted 0 ms 0 KB -