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;
vector <ll> u=U;
vector <ll> v=V;
ll a=A;
ll b=B;
int m=u.size();
for (ll i=0; i<m; i++){
g[u[i]].push_back({v[i],i});
g[v[i]].push_back({u[i],i});
}
vector <ll> query(m,0ll);
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 <ll> query(m,0ll);
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 <ll> 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);
}
}
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:19:16: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
19 | vector <ll> u=U;
| ^
highway.cpp:20:16: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
20 | vector <ll> v=V;
| ^
highway.cpp:29:11: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
29 | dist=ask(query)/a;
| ^~~~~
In file included from highway.cpp:1:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
7 | long long ask(const std::vector<int> &w);
| ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (ll i=0; i<possible.size(); i++){
| ~^~~~~~~~~~~~~~~~
highway.cpp:43:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (i<(possible.size()/2)) f.push_back(possible[i]);
| ~^~~~~~~~~~~~~~~~~~~~
highway.cpp:48:12: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
48 | if (ask(query)==a*dist) possible=s;
| ^~~~~
In file included from highway.cpp:1:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
7 | long long ask(const std::vector<int> &w);
| ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i=0; i<poss.size(); i++){
| ~^~~~~~~~~~~~
highway.cpp:57:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if (i<(poss.size()/2)) f.push_back(poss[i]);
| ~^~~~~~~~~~~~~~~~
highway.cpp:62:12: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
62 | if (ask(query)==a*dist) poss=s;
| ^~~~~
In file included from highway.cpp:1:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
7 | long long ask(const std::vector<int> &w);
| ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:22:5: warning: unused variable 'b' [-Wunused-variable]
22 | ll b=B;
| ^