Submission #760821

#TimeUsernameProblemLanguageResultExecution timeMemory
760821Sohsoh84Parachute rings (IOI12_rings)C++17
17 / 100
1536 ms123088 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define X first #define Y second #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; const ll MAXC = 5; int n, mx[MAXC], par[MAXC][MAXN], ig[MAXN], deg[MAXC][MAXN], sz[MAXC][MAXN], cyc_cnt[MAXC], cyc_sz[MAXC], cmp = 1; bool deg_ex; vector<int> poss, adj[MAXN]; vector<pll> edges; int find(int ind, int v) { return par[ind][v] == v ? v : par[ind][v] = find(ind, par[ind][v]); } inline void unite(int ind, int u, int v) { if (u == ig[ind] || v == ig[ind]) return; deg[ind][u]++; deg[ind][v]++; mx[ind] = max(mx[ind], deg[ind][u]); mx[ind] = max(mx[ind], deg[ind][v]); u = find(ind, u), v = find(ind, v); if (u == v) { cyc_cnt[ind]++; cyc_sz[ind] += sz[ind][u]; return; } par[ind][v] = u; sz[ind][u] += sz[ind][v]; } inline void init(int ind, int v = 0) { ig[ind] = v; for (int i = 1; i <= n; i++) { par[ind][i] = i; sz[ind][i] = 1; deg[ind][i] = 0; } mx[ind] = 0; cyc_cnt[ind] = 0; cyc_sz[ind] = 0; for (auto [u, v] : edges) unite(ind, u, v); } void Init(int N_) { n = N_; deg_ex = false; init(0); } inline void check(int v) { if (deg_ex) return; if (int(adj[v].size()) > 2) { deg_ex = true; poss.push_back(v); for (int u : adj[v]) poss.push_back(u); cmp = poss.size(); for (int i = 0; i < cmp; i++) init(i, poss[i]); } } void Link(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); check(u); check(v); for (int i = 0; i < cmp; i++) unite(i, u, v); edges.push_back({u, v}); } int CountCritical() { if (!deg_ex) { if (cyc_cnt[0] == 0) return n; else if (cyc_cnt[0] == 1) return cyc_sz[0]; return 0; } int ans = 0; for (int i = 0; i < cmp; i++) if (mx[i] <= 2 && cyc_cnt[i] == 0) ans++; 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...