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>
using namespace std;
const int MAXN=90005;
int n,m,par[MAXN];
vector <int> v[MAXN];
vector <pair<int,int> > vv;
map <pair<int,int>, int> r;
long long ANS;
void dfs (int x,int p,int l)
{
vv.push_back({l,x});
par[x]=p;
for (int i=0;i<v[x].size();i++)
{
if (v[x][i]!=p)
{
dfs(v[x][i],x,l+1);
}
}
}
void find_pair (int N, vector<int> U, vector<int> V, int A, int B)
{
n=N;
m=U.size();
vector<int> w;
w.resize(m);
ANS=ask(w);
for (int i=0;i<m;i++)
{
v[U[i]].push_back(V[i]);
v[V[i]].push_back(U[i]);
r[{U[i],V[i]}]=i;
r[{V[i],U[i]}]=i;
}
dfs(0,-1,1);
int low=0,high=vv.size(),mid,ans=-1;
while (low<=high)
{
for (int i=0;i<w.size();i++)
w[i]=0;
mid=(low+high)/2;
for (int i=mid;i<vv.size();i++)
{
int a=vv[i].second;
w[r[{a,par[a]}]]=1;
}
if (ask(w)!=ANS)
{
ans=vv[mid].second;
low=mid+1;
}
else
high=mid-1;
}
answer(0,ans);
}
Compilation message (stderr)
highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:14:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<w.size();i++)
~^~~~~~~~~
highway.cpp:43:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=mid;i<vv.size();i++)
~^~~~~~~~~~
# | 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... |