Submission #789857

# Submission time Handle Problem Language Result Execution time Memory
789857 2023-07-22T06:18:19 Z PoonYaPat Parachute rings (IOI12_rings) C++14
100 / 100
1792 ms 183624 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n,p[1000005],r[1000005],lst=-1,deg[1000005];
vector<int> adj[1000005],br;
vector<pii> edge;
set<int> ans;
bool nope=false,vis[1000005];
vector<int> st;

void dfs(int x, int par, int tar) {
  st.push_back(x);
  vis[x]=true;
  if (x==tar) for (auto s : st) br.push_back(s);
  else for (auto s : adj[x]) if (s!=par && !vis[s]) dfs(s,x,tar);
  st.pop_back();
}

int find(int x) {
  while (x!=p[x]) x=p[x];
  return x;
}

void unite(int a, int b) {
  a=find(a); b=find(b);
  if (r[a]<r[b]) swap(a,b);
  p[b]=a;
  if (r[a]==r[b]) ++r[a];
}

void Init(int N_) {
  n=N_;
  for (int i=0; i<n; ++i) ans.insert(i), p[i]=i;
}

void add(vector<int> x) {
  set<int> temp;
  for (auto s : x) if (ans.find(s)!=ans.end()) temp.insert(s);
  swap(temp,ans);
}

void Link(int A, int B) {
  if (nope) return;
  
  if (lst==-1) {
    if (find(A)==find(B)) {
      memset(vis,0,sizeof(vis));
      br.clear();
      dfs(A,-1,B);
      add(br);
    } else unite(A,B);

    adj[A].push_back(B);
    adj[B].push_back(A);
    edge.push_back(pii(A,B));

    if (adj[A].size()==3) add({adj[A][0],adj[A][1],adj[A][2],A});
    else if (adj[A].size()==4) for (auto s : adj[A]) if (ans.find(s)!=ans.end()) ans.erase(ans.find(s));

    if (adj[B].size()==3) add({adj[B][0],adj[B][1],adj[B][2],B});
    else if (adj[B].size()==4) for (auto s : adj[B]) if (ans.find(s)!=ans.end()) ans.erase(ans.find(s));

    if (ans.size()==0) nope=true;
    if (ans.size()==1) {
      lst=*(ans.begin());

      for (int i=0; i<n; ++i) p[i]=i;
      for (auto s : edge) {
        if (s.first!=lst && s.second!=lst) {
          ++deg[s.first]; ++deg[s.second];
          unite(s.first,s.second);
        }
      }
    }

  } else {
    if (A!=lst && B!=lst) {
      ++deg[A];
      ++deg[B];
      if (deg[A]>2 || deg[B]>2 || find(A)==find(B)) nope=true;
      unite(A,B);
    }
  }

}

int CountCritical() {
  if (nope) return 0;
  return ans.size();
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 16 ms 24116 KB Output is correct
3 Correct 14 ms 24160 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 16 ms 25192 KB Output is correct
6 Correct 16 ms 25676 KB Output is correct
7 Correct 12 ms 23992 KB Output is correct
8 Correct 14 ms 25204 KB Output is correct
9 Correct 14 ms 24164 KB Output is correct
10 Correct 14 ms 24276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 369 ms 72540 KB Output is correct
2 Correct 441 ms 87096 KB Output is correct
3 Correct 344 ms 79104 KB Output is correct
4 Correct 914 ms 118576 KB Output is correct
5 Correct 880 ms 121312 KB Output is correct
6 Correct 1792 ms 183624 KB Output is correct
7 Correct 337 ms 79284 KB Output is correct
8 Correct 800 ms 108696 KB Output is correct
9 Correct 856 ms 120060 KB Output is correct
10 Correct 694 ms 113100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 16 ms 24116 KB Output is correct
3 Correct 14 ms 24160 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 16 ms 25192 KB Output is correct
6 Correct 16 ms 25676 KB Output is correct
7 Correct 12 ms 23992 KB Output is correct
8 Correct 14 ms 25204 KB Output is correct
9 Correct 14 ms 24164 KB Output is correct
10 Correct 14 ms 24276 KB Output is correct
11 Correct 15 ms 25172 KB Output is correct
12 Correct 17 ms 25812 KB Output is correct
13 Correct 18 ms 25684 KB Output is correct
14 Correct 14 ms 24404 KB Output is correct
15 Correct 16 ms 25020 KB Output is correct
16 Correct 17 ms 25808 KB Output is correct
17 Correct 16 ms 25472 KB Output is correct
18 Correct 17 ms 25104 KB Output is correct
19 Correct 17 ms 25940 KB Output is correct
20 Correct 16 ms 24876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 16 ms 24116 KB Output is correct
3 Correct 14 ms 24160 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 16 ms 25192 KB Output is correct
6 Correct 16 ms 25676 KB Output is correct
7 Correct 12 ms 23992 KB Output is correct
8 Correct 14 ms 25204 KB Output is correct
9 Correct 14 ms 24164 KB Output is correct
10 Correct 14 ms 24276 KB Output is correct
11 Correct 15 ms 25172 KB Output is correct
12 Correct 17 ms 25812 KB Output is correct
13 Correct 18 ms 25684 KB Output is correct
14 Correct 14 ms 24404 KB Output is correct
15 Correct 16 ms 25020 KB Output is correct
16 Correct 17 ms 25808 KB Output is correct
17 Correct 16 ms 25472 KB Output is correct
18 Correct 17 ms 25104 KB Output is correct
19 Correct 17 ms 25940 KB Output is correct
20 Correct 16 ms 24876 KB Output is correct
21 Correct 33 ms 28172 KB Output is correct
22 Correct 44 ms 30660 KB Output is correct
23 Correct 53 ms 32452 KB Output is correct
24 Correct 43 ms 30104 KB Output is correct
25 Correct 34 ms 30028 KB Output is correct
26 Correct 44 ms 30312 KB Output is correct
27 Correct 52 ms 33132 KB Output is correct
28 Correct 41 ms 30636 KB Output is correct
29 Correct 51 ms 30248 KB Output is correct
30 Correct 66 ms 36800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 16 ms 24116 KB Output is correct
3 Correct 14 ms 24160 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 16 ms 25192 KB Output is correct
6 Correct 16 ms 25676 KB Output is correct
7 Correct 12 ms 23992 KB Output is correct
8 Correct 14 ms 25204 KB Output is correct
9 Correct 14 ms 24164 KB Output is correct
10 Correct 14 ms 24276 KB Output is correct
11 Correct 369 ms 72540 KB Output is correct
12 Correct 441 ms 87096 KB Output is correct
13 Correct 344 ms 79104 KB Output is correct
14 Correct 914 ms 118576 KB Output is correct
15 Correct 880 ms 121312 KB Output is correct
16 Correct 1792 ms 183624 KB Output is correct
17 Correct 337 ms 79284 KB Output is correct
18 Correct 800 ms 108696 KB Output is correct
19 Correct 856 ms 120060 KB Output is correct
20 Correct 694 ms 113100 KB Output is correct
21 Correct 15 ms 25172 KB Output is correct
22 Correct 17 ms 25812 KB Output is correct
23 Correct 18 ms 25684 KB Output is correct
24 Correct 14 ms 24404 KB Output is correct
25 Correct 16 ms 25020 KB Output is correct
26 Correct 17 ms 25808 KB Output is correct
27 Correct 16 ms 25472 KB Output is correct
28 Correct 17 ms 25104 KB Output is correct
29 Correct 17 ms 25940 KB Output is correct
30 Correct 16 ms 24876 KB Output is correct
31 Correct 33 ms 28172 KB Output is correct
32 Correct 44 ms 30660 KB Output is correct
33 Correct 53 ms 32452 KB Output is correct
34 Correct 43 ms 30104 KB Output is correct
35 Correct 34 ms 30028 KB Output is correct
36 Correct 44 ms 30312 KB Output is correct
37 Correct 52 ms 33132 KB Output is correct
38 Correct 41 ms 30636 KB Output is correct
39 Correct 51 ms 30248 KB Output is correct
40 Correct 66 ms 36800 KB Output is correct
41 Correct 232 ms 64808 KB Output is correct
42 Correct 453 ms 92448 KB Output is correct
43 Correct 325 ms 83260 KB Output is correct
44 Correct 334 ms 84360 KB Output is correct
45 Correct 426 ms 99588 KB Output is correct
46 Correct 561 ms 111008 KB Output is correct
47 Correct 1229 ms 155032 KB Output is correct
48 Correct 357 ms 87120 KB Output is correct
49 Correct 624 ms 120000 KB Output is correct
50 Correct 727 ms 118956 KB Output is correct
51 Correct 293 ms 75340 KB Output is correct
52 Correct 297 ms 73216 KB Output is correct
53 Correct 334 ms 86052 KB Output is correct
54 Correct 610 ms 101684 KB Output is correct
55 Correct 422 ms 88148 KB Output is correct