This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
using pii = pair<int, int>;
int my_query(const set<int> &s) {
vector<int> v;
for (auto &it : s)
v.push_back(it);
return query(v);
}
int findEgg(int n, vector<pii> bridges) {
vector<vector<int>> g(n + 1);
vector<bool> vis(n + 1);
vector<int> euler;
for (auto [ x, y ] : bridges) {
g[x].push_back(y);
g[y].push_back(x);
}
function<void(int)> dfs = [&](int x) {
vis[x] = true;
euler.push_back(x);
for (auto u : g[x]) {
if (!vis[u]) {
dfs(u);
euler.push_back(x);
}
}
};
dfs(1);
function<bool(int)> check = [&](int mid) {
set<int> s;
for (int i = 0; i < mid; i++)
s.insert(euler[i]);
return !my_query(s);
};
int l = 1, r = int(euler.size()) - 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
return euler[r];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |