Submission #425225

#TimeUsernameProblemLanguageResultExecution timeMemory
425225wiwihoParachute rings (IOI12_rings)C++14
55 / 100
4019 ms108916 KiB
#include <bits/stdc++.h> #define eb emplace_back #define printv(a, b) {\ for(auto pv : a) b << pv << " ";\ b << "\n";\ } using namespace std; int n; vector<vector<int>> g; vector<int> in, low; vector<int> pr; void Init(int N){ n = N; g.resize(n); } void Link(int u, int v){ g[u].eb(v); g[v].eb(u); } int ts = 0; void dfs(int now, int p){ in[now] = ts++; low[now] = in[now]; pr[now] = p; for(int i : g[now]){ if(in[i] != -1){ low[now] = min(low[now], in[i]); continue; } dfs(i, now); low[now] = min(low[now], low[i]); } } int CountCritical(){ ts = 0; in.clear(); low.clear(); pr.clear(); in.resize(n, -1); low.resize(n); pr.resize(n); int con = 0; for(int i = 0; i < n; i++){ if(in[i] != -1) continue; con++; dfs(i, i); } int zero = 0, one = 0, two = 0, more = 0; for(int i = 0; i < n; i++){ int deg = g[i].size(); if(deg == 0) zero++; else if(deg == 1) one++; else if(deg == 2) two++; else more++; } int ans = 0; /*cerr << "query " << one << " " << two << " " << more << " " << con << "\n"; printv(in, cerr); printv(low, cerr); printv(pr, cerr);*/ for(int i = 0; i < n; i++){ int deg = g[i].size(); if(deg == 0) zero--; else if(deg == 1) one--; else if(deg == 2) two--; else more--; for(int j : g[i]){ int d = g[j].size(); if(d == 0) zero--; else if(d == 1) one--; else if(d == 2) two--; else more--; if(d - 1 == 0) zero++; else if(d - 1 == 1) one++; else if(d - 1 == 2) two++; else more++; if(pr[j] == i && low[j] >= in[i]) con++; } if(pr[i] == i) con--; //cerr << "test " << i << "\n"; //cerr << one << " " << two << " " << more << " " << con << "\n"; if(more == 0 && one == (con - zero) * 2) ans++; if(deg == 0) zero++; else if(deg == 1) one++; else if(deg == 2) two++; else more++; for(int j : g[i]){ int d = g[j].size(); if(d == 0) zero++; else if(d == 1) one++; else if(d == 2) two++; else more++; if(d - 1 == 0) zero--; else if(d - 1 == 1) one--; else if(d - 1 == 2) two--; else more--; if(pr[j] == i && low[j] >= in[i]) con--; } if(pr[i] == i) con++; } return ans; }
#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...