Submission #389265

#TimeUsernameProblemLanguageResultExecution timeMemory
389265cheissmartEaster Eggs (info1cup17_eastereggs)C++14
0 / 100
13 ms456 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]; } pi c; void get_c(int u, int p = 0) { for(int v:G[u]) if(v != p && !vis[v]) { if(abs(sz[v] - (tot - sz[v])) <= 1) { c = {u, v}; } get_c(v, u); } } 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); if(tot == 1) return u; get_c(u); int x = c.F, y = c.S; //cerr << x << ", " << y << endl; s.clear(); dfs(y, x); if(query(s)) { vis[x] = 1; return go(y); } else { vis[y] = 1; return go(x); } } 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...