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"highway.h"
#include<bits/stdc++.h>
#ifndef EVAL
#include"grader.cpp"
#endif
using namespace std;
vector<pair<int,int>>g[90005];
vector<int>grp[90005];
int id[90005],mx,up[90005];
long long pivot;
void dfs(int v,int p,int depth){
mx=max(mx,depth);
grp[depth].push_back(id[v]);
for(auto to:g[v])if(to.first!=p){
id[to.first]=to.second;
up[to.second]=to.first;
dfs(to.first,v,depth+1);
}
}
void find_pair(int n,vector<int>x,vector<int>y,int a,int b){
for(int i=0;i<n-1;i++){
g[x[i]].push_back({y[i],i});
g[y[i]].push_back({x[i],i});
}
vector<int>v(n-1,0);
pivot=ask(v);
dfs(0,0,0);
int l=1,r=mx;
while(l<r){
//cout<<l<<"_"<<r;
int mid=(l+r+1)>>1;
vector<int>v(n-1,0);
//cout<<"_"<<mid<<"\n";
for(int i=mid;i<=mx;i++){
//cout<<"DEPTH:"<<i;
for(auto to:grp[i]){
//cout<<" "<<to;
v[to]=1;
}
//cout<<endl;
}
//cout<<"QUERY:";
//for(auto to:v)cout<<to;
//cout<<" "<<ask(v)<<endl;
if(ask(v)!=pivot)l=mid;
else r=mid-1;
}
int uid=l;
//cout<<uid<<endl;
l=0,r=grp[uid].size()-1;
while(l<r){
int mid=(l+r)>>1;
vector<int>v(n-1,0);
for(int i=l;i<=mid;i++)v[grp[uid][i]]=1;
if(ask(v)!=pivot)r=mid;
else l=mid+1;
}
int s=up[grp[uid][l]];
answer(0,s);
}
/*
5 4 1 2 0 4
0 1
0 2
1 3
1 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |