Submission #1051482

#TimeUsernameProblemLanguageResultExecution timeMemory
1051482abczzParachute rings (IOI12_rings)C++17
37 / 100
1411 ms187932 KiB
#include <iostream> #include <map> #include <vector> #define ll long long using namespace std; map <ll, ll> mp; vector <ll> adj[1000000], V; ll n, x, y, tot, P[1000000], cyc[1000000], deg[1000000]; ll dsu(ll u) { if (P[u] == u) return u; else return P[u] = dsu(P[u]); } void Init(int N_) { n = N_; tot = 0; mp.clear(); for (int i=0; i<n; ++i) { adj[i].clear(); P[i] = i; ++mp[i]; } } bool dfs(ll u, ll p, ll x) { bool res = 0; for (auto v : adj[u]) { if (v != p) { if (v != x && V.empty()) res |= dfs(v, u, x); else { if (mp.count(u)) V.push_back(u); return 1; } } } if (res && mp.count(u)) V.push_back(u); return res; } void Link(int A, int B) { if (mp.empty()) return; ++deg[A], ++deg[B]; adj[A].push_back(B); adj[B].push_back(A); x = dsu(A), y = dsu(B); if (x == y) { ++cyc[x]; ++tot; if (cyc[x] == 1) { V.clear(); dfs(A, -1, A); mp.clear(); for (auto u : V) ++mp[u]; } } else { P[x] = y; if (cyc[x] && cyc[y]) { mp.clear(); return; } cyc[y] += cyc[x]; } if (deg[A] > 3) { if (mp.count(A)) { mp.clear(); ++mp[A]; } else mp.clear(); } else if (deg[A] == 3) { V.clear(); if (mp.count(A)) V.push_back(A); for (auto v : adj[A]) { if (mp.count(v)) V.push_back(v); } mp.clear(); for (auto u : V) ++mp[u]; } if (deg[B] > 3) { if (mp.count(B)) { mp.clear(); ++mp[B]; } else mp.clear(); } else if (deg[B] == 3) { V.clear(); if (mp.count(B)) V.push_back(B); for (auto v : adj[B]) { if (mp.count(v)) V.push_back(v); } mp.clear(); for (auto u : V) ++mp[u]; } if (tot > 1) { V.clear(); for (auto [x, y] : mp) { if (deg[x] >= 3) V.push_back(x); } mp.clear(); for (auto u : V) ++mp[u]; } } int CountCritical() { return mp.size(); }
#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...