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;
vector<vector<int>> ve;
vector<int> w;
void dfs(int x, int p){
w.push_back(x);
for (auto el : ve[x]){
if (el != p){
dfs(el, x);
}
}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
w.clear();
ve.clear();
ve.resize(N + 1);
for (auto el : bridges){
ve[el.first].push_back(el.second);
ve[el.second].push_back(el.first);
}
dfs(1, -1);
int l = 1, r = N;
while (l <= r){
int mid = (l + r) / 2;
vector<int> rec;
for (int i = 0; i < mid; i++){
rec.push_back(w[i]);
}
bool a = query(rec);
if (a && r - l == 0){
return w[l - 1];
}
if (a){
r = mid - 1;
}
else{
l = mid + 1;
}
}
return w[l - 1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |