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 "highway.h"
#define N 200009
#define pii pair <int, int>
#define ff first
#define ss second
#define sz size
#define pb push_back
#define ll long long
using namespace std;
int n, m, ln;
vector<int>e[N];
vector<int>asd;
map<int, int>c[N];
int ansS, ansT;
void find_pair(int NN, std::vector<int>u, std::vector<int>v, int a, int b){
n=NN;
m=u.size();
for(int i=0; i<m; i++){
e[u[i]].pb(v[i]);
e[v[i]].pb(u[i]);
c[v[i]][u[i]]=i;
c[u[i]][v[i]]=i;
asd.pb(0);
}
ln=ask(asd);
int l=0, r=m-1;
int x, in;
while(r>=l){
int md=(l+r)/2;
for(int i = 0; i < m; i++) asd[i] = 0;
for(int i=0; i<=md; i++) asd[i]=1;
x=ask(asd);
if(x==ln) l=md+1;
else in = md, r=md-1;
}
// answer(0, 0);
// return;
queue<int> q;
queue<int> q2;
q.push(u[in]);
q2.push(v[in]);
int vis[N];
vis[u[in]]=1, vis[v[in]]=1;
vector<int> p;
int lft=0, rgt=0;
while(!q.empty() and !q2.empty()){
if(!lft){
p.clear();
int nd=q.front();
q.pop();
for(auto i:e[nd])
if(!vis[i])
vis[i]=vis[nd]+1, p.pb(i), q.push(i);
sort(p.begin(), p.end());
for(int i=0; i<m; i++)
asd[i]=0;
for(auto i:p)
for(auto j:e[i]) asd[c[i][j]]=1;
x=ask(asd);
if(x!=ln){
l=0, r=p.sz()-1;
while(l>=r){
int md=(l+r)/2;
for(int i=0; i<m; i++)
asd[i]=0;
for(int i=0; i<=md; i++)
for(auto j:e[p[i]]) asd[c[p[i]][j]]=1;
x=ask(asd);
if(x!=ln)
in=md, r=md-1;
else l=md+1;
}
ansS=p[in];
lft=1;
}
}
if(!rgt){
p.clear();
int nd=q2.front();
q2.pop();
for(auto i:e[nd])
if(!vis[i])
vis[i]=vis[nd]+1, p.pb(i), q2.push(i);
sort(p.begin(), p.end());
for(int i=0; i<m; i++)
asd[i]=0;
for(auto i:p)
for(auto j:e[i]) asd[c[i][j]]=1;
x=ask(asd);
if(x!=ln){
l=0, r=p.sz()-1;
while(l>=r){
int md=(l+r)/2;
for(int i=0; i<m; i++)
asd[i]=0;
for(int i=0; i<=md; i++)
for(auto j:e[p[i]]) asd[c[p[i]][j]]=1;
x=ask(asd);
if(x!=ln)
in=md, r=md-1;
else l=md+1;
}
ansT=p[in];
rgt=1;
}
}
}
answer(ansS, ansT);
}
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:49:13: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | q.push(u[in]);
| ^
# | 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... |