# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
293985 | Dovran | Highway Tolls (IOI18_highway) | C++11 | 0 ms | 0 KiB |
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;
}
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, p2;
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){
p2.clear();
int nd2=q2.front();
q2.pop();
for(auto i:e[nd2])
if(!vis[i])
vis[i]=vis[nd2]+1, p2.pb(i), q2.push(i);
sort(p2.begin(), p2.end());
for(int i=0; i<m; i++)
asd[i]=0;
for(auto i:p2)
for(auto j:e[i.ss]) asd[c[i][j]]=1;
x=ask(asd);
if(ask(asd)!=ln){
l=0, r=p2.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[p2[i]]) asd[c[p2[i]][j]]=1;
x=ask(asd);
if(x!=ln)
in=md, r=md-1;
else l=md+1;
}
ansT=p2[in];
rgt=1;
}
}
}
answer(ansS, ansT);
}