Submission #389242

#TimeUsernameProblemLanguageResultExecution timeMemory
389242cheissmartEaster Eggs (info1cup17_eastereggs)C++14
10 / 100
20 ms472 KiB
#include <bits/stdc++.h> #include "grader.h" #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "LINE(" << __LINE__ << "): " << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 520; vi G[N]; int vis[N], sz[N], tot; void init(int n) { for(int i = 1; i <= n; i++) { G[i].clear(); vis[i] = 0; } } int dfs_sz(int u, int p = 0) { sz[u] = 1; for(int v:G[u]) if(v != p && !vis[v]) { sz[u] += dfs_sz(v, u); } return sz[u]; } int get_c(int u, int p = 0) { int mx = 0; for(int v:G[u]) if(v != p && !vis[v]) { int cc = get_c(v, u); mx = max(mx, sz[v]); if(cc) return cc; } if(max(mx, tot - sz[u]) * 2 <= tot) return u; return 0; } vi s; void dfs(int u, int p) { s.PB(u); for(int v:G[u]) if(v != p && !vis[v]) dfs(v, u); } int go(int u) { tot = dfs_sz(u); int c = get_c(u); for(int v:G[c]) if(!vis[v]) { s.clear(); dfs(v, c); if(query(s)) { vis[c] = 1; return go(v); } } return c; } int findEgg(int n, V<pi> es) { init(n); for(pi p:es) G[p.F].PB(p.S), G[p.S].PB(p.F); return go(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...