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>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int query(vector<int> f);
int findEgg(int n, vector<pii> ed){
vector<int> g[n];
for (auto [x, y]: ed){
x--; y--;
g[x].pb(y); g[y].pb(x);
}
vector<int> a(n);
int timer = 0;
function<void(int, int)> dfs = [&](int v, int pr){
a[timer++] = v;
for (int i: g[v]){
if (i == pr) continue;
dfs(i, v);
}
};
dfs(0, 0);
auto check = [&](int x){
vector<int> f;
for (int i = 0; i <= x; i++){
f.pb(a[i]);
}
return query(f);
};
int l = 0, r = n - 1;
while (l + 1 < r){
int m = (l + r) / 2;
if (check(m)){
r = m;
}
else {
l = m + 1;
}
}
if (check(l)) r = l;
return a[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... |