Submission #15785

#TimeUsernameProblemLanguageResultExecution timeMemory
15785myungwoo낙하산 고리들 (IOI12_rings)C++14
100 / 100
2403 ms52392 KiB
#include <vector> using namespace std; #define MAXN 1000006 #define mp make_pair #define pb push_back #define sz(v) ((int)(v).size()) typedef pair<int,int> pii; static int N,deg[MAXN],par[MAXN],size[MAXN]; static int _par[4][MAXN],_deg[4][MAXN],_target[4]; static int cycle_cnt,cycle_size; static bool sw,_valid[4]; static vector<pii> edges; int find(int n,int p[MAXN]=par){ return p[n]==n?n:(p[n]=find(p[n],p)); } void Init(int n) { int i; N = n; for (i=1;i<=N;i++) par[i] = i, size[i] = 1; } void addEdge(int a,int b) { int i; for (i=0;i<4;i++){ if (_target[i] == a || _target[i] == b) continue; if (++_deg[i][a] == 3) _valid[i] = 0; if (++_deg[i][b] == 3) _valid[i] = 0; int p = find(a,_par[i]), q = find(b,_par[i]); if (p == q) _valid[i] = 0; _par[i][q] = p; } } void reg(int n) { int i,j,k=0; _target[k++] = n; for (i=0;i<sz(edges);i++){ if (edges[i].first == n) _target[k++] = edges[i].second; if (edges[i].second == n) _target[k++] = edges[i].first; } for (i=0;i<4;i++){ _valid[i] = 1; for (j=1;j<=N;j++) _par[i][j] = j; } for (i=0;i<sz(edges);i++) addEdge(edges[i].first,edges[i].second); } void Link(int a,int b) { a++; b++; deg[a]++; deg[b]++; edges.pb(mp(a,b)); if (!sw && deg[a] == 3) sw = 1, reg(a); else if (!sw && deg[b] == 3) sw = 1, reg(b); else if (!sw){ a = find(a); b = find(b); if (a == b){ cycle_cnt++; cycle_size = size[a]; }else{ par[b] = a; size[a] += size[b]; } }else{ addEdge(a,b); } } int CountCritical() { if (cycle_cnt > 1) return 0; if (!sw){ if (cycle_cnt) return cycle_size; return N; } int ret = 0,i; for (i=0;i<4;i++) ret += _valid[i]; return ret; }
#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...