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"
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
using namespace std;
/*
static int N, X, cntQ;
static vector < int > v[1009];
int query (vector < int > h)
{
    cntQ ++;
    int ap[1009];
    if (h.empty ()) return 0;
    for (int i=1; i<=N; i++)
        ap[i] = 0;
    for (auto it = h.begin (); it != h.end (); it ++)
        ap[*it] = 1;
    queue < int > cc;
    cc.push (h[0]), ap[h[0]] = 2;
    while (!cc.empty ())
    {
        int nod = cc.front ();
        cc.pop ();
        for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
            if (ap[*it] == 1)
                ap[*it] = 2, cc.push (*it);
    }
    for (int i=1; i<=N; i++)
        if (ap[i] == 1) return -1;
    for (auto it = h.begin (); it != h.end (); it ++)
        if (*it == X) return 1;
    return 0;
}*/
//----------------------------
const int maxn = 512;
int tim, st[maxn];
vector <int> adj[maxn];
void dfs(int x, int p = -1) {
	st[tim++] = x;
	for (int y : adj[x]) if (y != p) dfs(y, x);
}
int findEgg(int n, vector <pii> e) {
	tim = 0;
	for (int i = 0; i < n; i++) adj[i].clear();
	for (int i = 0; i < n-1; i++) {
		adj[e[i].F-1].pb(e[i].S-1);
		adj[e[i].S-1].pb(e[i].F-1);
	}
	int lo = 0, hi = n-1;
	dfs(0);
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		vector <int> v;
		for (int i = 0; i <= mid; i++) v.pb(st[i]+1);
		if (query(v)) hi = mid;
		else lo = mid+1;
	}
	return st[lo]+1;
}
//----------------------------
/*
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d", &N);
int Queries;
vector < pair < int, int > > param;
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
    param.push_back ({x, y});
}
scanf ("%d", &Queries);
while (Queries --)
{
    scanf ("%d", &X), cntQ = 0;
    int Y = findEgg (N, param);
    if (X != Y)
    {
        printf ("WA %d instead of %d\n", Y, X);
        return 0;
    }
    printf ("OK %d\n", cntQ);
}
return 0;
}*/
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |