# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
438941 | leinad2 | Highway Tolls (IOI18_highway) | C++17 | 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 "highway.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int> >adj[90010];
int vis[90010];
void find_pair(int N, vector<int>U, vector<int>V, int A, int B)
{
int M=U.size();
vector<int>w(M);long long X=ask(w);
for(int i=0;i<M;i++)
{
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
int s=0;int e=M-1;
while(s<e)
{
int m=s+e>>1;
for(int i=0;i<M;i++)w[i]=0;
for(int i=0;i<=m;i++)w[i]=1;
if(ask(w)>X)e=m;
else s=m+1;
}
int S=U[s], E=V[s];
queue<pair<int, int> >q;
q.push({S, 0});
q.push({E, 1});
vis[S]=vis[E]=1;
vector<pair<int, int> >v1, v2;
while(q.size())
{
int a=q.front().first;int b=q.front().second;q.pop();
for(int i=0;i<adj[a].size();i++)
{
int p=adj[a][i].first;
if(vis[p])continue;
vis[p]=1;q.push({p, b});
if(b==0)v1.push_back(adj[a][i]);
else v2.push_back(adj[a][i]);
}
}
int ans1;
if(v1.size())
{
int a=0;int b=v1.size()-1;
while(a<b)
{
int m=a+b+1>>1;
for(int i=0;i<M;i++)w[i]=0;
for(int i=m;i<=b;i++)w[v1[i].second]=1;
if(ask(w)>X)a=m;
else b=m-1;
}
ans1=v1[a].first;
}
else ans1=S;
int ans2;
if(v2.size())
{
int a=0;int b=v2.size()-1;
while(a<b)
{
int m=a+b+1>>1;
for(int i=0;i<M;i++)w[i]=0;
for(int i=m;i<=b;i++)w[v2[i].second]=1;
if(ask(w)>X)a=m;
else b=m-1;
}
ans2=v2[a].first;
}
else ans2=E;
answer(ans1, ans2);
}