Submission #500569

#TimeUsernameProblemLanguageResultExecution timeMemory
500569sidonParachute rings (IOI12_rings)C++17
100 / 100
471 ms48288 KiB
#include <bits/stdc++.h> using namespace std; #define F(X, Y) for(int X = 0; X < Y; X++) array<int, 2> g[1<<20]; int N, p, j; struct Solver { int e[1<<20], d[1<<20] = {}; int maxDeg = 0, cycle = -1, rem = -1; void add(int u, int v) { if(u == rem || v == rem || maxDeg > 2) return; maxDeg = max({maxDeg, ++d[u], ++d[v]}); while(e[u] >= 0) u = e[u]; while(e[v] >= 0) v = e[v]; if(u == v) cycle = cycle < 0 ? u : N; else { if(e[u] > e[v]) swap(u, v); e[u] += e[v], e[v] = u; } } int get() { if(maxDeg > 2) return 0; return cycle < 0 ? N : e[cycle]; } } s[5]; void Init(int n) { F(i, 5) fill(s[i].e, s[i].e+(N=n), -1); } void Link(int A, int B) { if(!p) { s[0].add(A, B); g[j++] = {A, B}; if(s[0].maxDeg > 2) { F(i, N) if(s[0].d[i] > 2) s[p=1].rem = i; F(k, j) F(i, 2) if(g[k][i] == s[1].rem) s[++p].rem = g[k][!i]; F(i, 4) F(k, j) s[i+1].add(g[k][0], g[k][1]); } } else F(i, 4) s[i+1].add(A, B); } int CountCritical() { int res = 0; if(p) F(i, 4) res += s[i+1].get() > 0; else res = abs(s[0].get()); return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...