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;
#define ff first
#define ss second
#define pb push_back
//#define int long long
// static int N, X, cntQ;
// static vector < int > v[1009];
int timer=0,l,r,mid,ans;
pair <int,int> tin[1024];
vector <int> adj[1024],v1;
// 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;
// }
void dfs(int x,int p){
tin[x]=make_pair(timer++,x);
for(auto u:adj[x]){
if(u!=p){
dfs(u,x);
}
}
}
int findEgg(int n,vector < pair <int,int> > bridges){
timer=0;
for(int i=1;i<=n;i++){
adj[i].clear();
}
for(int i=0;i<=n-2;i++){
adj[bridges[i].ff].pb(bridges[i].ss);
adj[bridges[i].ss].pb(bridges[i].ff);
}
dfs(1,0);
sort(tin+1,tin+n+1);
// for(int i=1;i<=n;i++){
// cout<<tin[i].ff<<"----"<<tin[i].ss<<endl;
// }
l=1;
r=n;
while(l<=r){
mid=(l+r)/2;
v1.clear();
for(int i=1;i<=mid;i++){
v1.pb(tin[i].ss);
// cout<<tin[i].ss<<" ";
}
// cout<<endl;
if(query(v1)==1){
ans=tin[mid].ss;
r=mid-1;
}else{
l=mid+1;
}
}
return ans;
}
// int main ()
// {
// //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... |