//#include "/Users/stdc++.h"
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define mp make_pair
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair < int, int >
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
typedef long double ld;
const int INF = 2e9;
const ll BIG_INF = 1e18;
const ll MOD = 1e9 + 7;
const int maxn = 550;
int verts[maxn], timer;
vector < int > g[maxn];
bool used[maxn];
void dfs(int v) {
used[v] = true;
verts[timer++] = v;
for (int j = 0; j < sz(g[v]); j++) {
int to = g[v][j];
if (!used[to])
dfs(to);
}
}
bool prov(int max_ind) {
vector < int > s;
for (int i = 0; i <= max_ind; i++)
s.pb(verts[i] + 1);
return query(s);
}
int bin_search() {
int l = -1, r = timer - 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (prov(m))
r = m;
else
l = m;
}
return verts[r];
}
int findEgg(int N, vector < pair < int, int > > bridges) {
for (int i = 0; i < N; i++) {
g[i].clear();
used[i] = false;
}
for (int i = 0; i < sz(bridges); i++) {
int u = bridges[i].fs, v = bridges[i].sc;
u--;
v--;
g[u].pb(v);
g[v].pb(u);
}
timer = 0;
dfs(0);
return bin_search() + 1;
}
Compilation message
Compilation timeout while compiling eastereggs