# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334079 | nicholask | Highway Tolls (IOI18_highway) | C++14 | 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>
#define x first
#define y second
#define ll long long
using namespace std;
vector <pair <ll,ll> > g[90000]; //first: connection to which node, second: edge no.
ll dist;
vector <pair <ll,ll> > poss;
void dfs(ll cur,ll prev,ll d){
for (auto&i:g[cur]){
if (i.x==prev) continue;
if (d+1==dist) poss.push_back({i.y,i.x});
else dfs(i.x,cur,d+1);
}
}
void find_pair(int N,vector <int> U,vector <int> V,int A,int B){
ll n=N;
ll m=u.size();
vector <ll> u;
for (ll i=0; i<m; i++) u[i]=U[i];
vector <ll> v;
for (ll i=0; i<m; i++) v[i]=V[i];
ll a=A;
ll b=B;
for (ll i=0; i<m; i++){
g[u[i]].push_back({v[i],i});
g[v[i]].push_back({u[i],i});
}
vector <int> query(m,0);
dist=ask(query)/a;
bool can=1;
for (ll i=0; i<m; i++){
if (u[i]!=i||v[i]!=i+1){
can=0;
break;
}
}
if (can){ //subtask 3
vector <ll> possible;
for (ll i=0; i<n; i++) possible.push_back(i);
while (possible.size()>1){
vector <ll> f,s;
for (ll i=0; i<possible.size(); i++){
if (i<(possible.size()/2)) f.push_back(possible[i]);
else s.push_back(possible[i]);
}
vector <int> query(m,0);
for (auto&i:f) query[i]=1;
if (ask(query)==a*dist) possible=s;
else possible=f;
}
answer(possible[0],possible[0]+dist);
} else {
dfs(0,-1,0);
while (poss.size()>1){
vector <pair <ll,ll> > f,s;
for (int i=0; i<poss.size(); i++){
if (i<(poss.size()/2)) f.push_back(poss[i]);
else s.push_back(poss[i]);
}
vector <int> query(m,0);
for (auto&i:f) query[i.x]=1;
if (ask(query)==a*dist) poss=s;
else poss=f;
}
answer(0,poss[0].y);
}
}