제출 #1097316

#제출 시각아이디문제언어결과실행 시간메모리
1097316bvv23Easter Eggs (info1cup17_eastereggs)C++14
100 / 100
16 ms600 KiB
#include <bits/stdc++.h> #include "grader.h" using namespace std; const int N = 600 + 7; vector <int> g[N]; vector <int> path; void dfs(int node, int p = - 1) { path.push_back(node); for (auto v : g[node]) { if (v != p) { dfs(v, node); } } } int findEgg (int n, vector <pair<int, int >> edges) { path.clear(); for (int i = 0; i <= n; i++) { g[i].clear(); } for (auto v : edges) { g[v.first].push_back(v.second); g[v.second].push_back(v.first); } dfs(1); int l = 0, r = n - 2; // if this current path is ok, then look for more min answer int ans = path.back(); vector <int> lst; while (l <= r) { int mid = (l + r) >> 1; lst.clear(); for (int i = 0; i <= mid; i++) { lst.push_back(path[i]); } if (query(lst)) { r = mid - 1; ans = lst.back(); } else { l = mid + 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...