Submission #389304

#TimeUsernameProblemLanguageResultExecution timeMemory
389304rk42745417Easter Eggs (info1cup17_eastereggs)C++17
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> #include "grader.h" //#include "grader.cpp" using namespace std; #define EMT ios::sync_with_stdio(0); cin.tie(0); using ll = int64_t; using ull = uint64_t; using uint = uint32_t; using ld = long double; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const ll LINF = 1e18; const double EPS = 1e-9; vector<vector<int>> edge; vector<int> sz; vector<int> que; vector<bool> ok; vector<bool> is; void init(int n) { edge.clear(); sz.clear(); is.clear(); edge.resize(n + 1); sz.resize(n + 1); is.resize(n + 1); } int dfs(int u, int p) { sz[u] = 1; for(int v : edge[u]) if(v != p && ok[v]) sz[u] += dfs(v, u); return sz[u]; } int centroid(int u, int p, int n) { for(int v : edge[u]) if(v != p && ok[v] && sz[v] > n / 2) return centroid(v, u, n); return u; } void go(int u, int p) { que.push_back(u); is[u] = 1; for(int v : edge[u]) if(v != p && ok[v]) go(v, u); } int solve(int u) { for(int a : que) is[a] = 0; que.clear(); int n = dfs(u, u); if(n == 1) return u; u = centroid(u, u, n); dfs(u, u); assert(sz[u] == n); que.push_back(u); is[u] = 1; int cur = 0; for(int v : edge[u]) { if(cur + sz[v] < n / 2) go(v, u); } assert(!que.empty()); int w = query(que); if(w) { for(int i = 1; i <= n; i++) if(!is[i]) ok[i] = 0; return solve(u); } else { for(int a : que) ok[a] = 0; for(int v : edge[u]) if(!is[v]) return solve(v); } assert(0); return 0; } int findEgg(int n, vector<pair<int, int>> edges) { init(n); for(int i = 1; i <= n; i++) ok[i] = 1; for(const auto &[a, b] : edges) edge[a].push_back(b), edge[b].push_back(a); return solve(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...