# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410434 | 2021-05-22T16:58:34 Z | nichke | Easter Eggs (info1cup17_eastereggs) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; vector<int> adj[513]; vector<int> euler; set<int> pref[513]; vector<int> vi; void dfs(int v, int p) { euler.push_back(v); for (int u : adj[v]) { if (u == p) continue; dfs(u, v); euler.push_back(v); } } int findEgg(int N, vector< pair <int, int> > bridges) { for (int i = 0; i < 513; i++) { adj[i].clear(); } for (auto it : bridges) { adj[it.first].push_back(it.second); adj[it.second].push_back(it.first); } dfs(1, 1); pref[0].insert(euler[0]); for (int i = 1; i < euler.size(); i++) { pref[i] = pref[i - 1]; pref[i].insert(euler[i]); } int l = 0, r = euler.size() - 1; int flag = -1; while (l <= r) { vi.clear(); int m = (l + r) / 2; for (int i : pref[m]) { vi.push_back(i); } int k = query(vi); if (k) { flag = m; r = m - 1; } else { l = m + 1; } } if (flag) { for (int i : pref[flag - 1]) { pref[flag].erase(i); } } for (int i : pref[flag]) { return i; } }