// #include "highway.h"
#include "grader.cpp"
#include <vector>
#include <map>
#include <utility>
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
const int maxn = (int)2e5 + 7;
vector < int > gr[maxn];
vector < int > nwgr[maxn];
vector < int > vec[maxn];
vector < int > w;
vector < int > del;
map < pair < int, int >, int > mp;
int id[maxn], h[maxn], p[maxn], idc[maxn];
int get(int a) {
if (id[a] == a) return a;
return id[a] = get(id[a]);
}
void connect(int a, int b) {
a = get(a);
b = get(b);
id[a] = b;
}
void addedge(int a, int b) {
nwgr[a].push_back(b);
nwgr[b].push_back(a);
}
void dfs(int v, int pr) {
vec[h[v]].push_back(v);
p[v] = pr;
idc[v] = mp[{v, pr}];
for (int to : nwgr[v]) {
if (to == pr) continue;
h[to] = h[v] + 1;
del.push_back(mp[{v, to}]);
w[del.back()] = 1;
dfs(to, v);
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int n = N;
int m = U.size();
ll dist = 0;
w.resize(m, 0);
dist = ask(w) / A;
for (int i = 0; i < n; i++) {
id[i] = i;
}
for (int i = 0; i < m; i++) {
int u, v;
u = U[i];
v = V[i];
mp[{v, u}] = mp[{u, v}] = i;
gr[u].push_back(v);
gr[v].push_back(u);
}
int l = -1;
int r = m - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
w[i] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
w[i] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
for (int i = 0; i < m; i++) {
w[i] = 1;
}
w[r] = 0;
int u, v;
u = U[r];
v = V[r];
del.push_back(r);
queue < int > q;
q.push(u);
q.push(v);
addedge(u, v);
connect(u, v);
while (!q.empty()) {
int asd = q.front();
q.pop();
for (int to : gr[asd]) {
if (get(to) != get(asd)) {
addedge(asd, to);
connect(asd, to);
w[mp[{asd, to}]] = 0;
q.push(to);
}
}
}
dfs(u, v);
ll asd = (ask(w) - dist * A) / (B - A);
for (int to : del) {
w[to] = 0;
}
del.clear();
l = -1;
r = vec[asd].size() - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
int s, t;
s = vec[asd][r];
for (int i = 0; i < n; i++) {
vec[i].clear();
}
h[s] = 0;
dfs(s, s);
for (int to : del) {
w[to] = 0;
}
asd = dist;
l = -1;
r = vec[asd].size() - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
t = vec[asd][r];
answer(s, t);
}
/*
7 7 1 1000 5 6
0 2
0 5
1 2
2 3
3 4
4 5
4 6
4 5 3 123 0 3
0 1
0 2
1 2
2 3
3 0
*/
Compilation message
/tmp/ccIvzb4o.o: In function `ask(std::vector<int, std::allocator<int> > const&)':
grader.cpp:(.text+0x70): multiple definition of `ask(std::vector<int, std::allocator<int> > const&)'
/tmp/ccBcvp20.o:highway.cpp:(.text+0x100): first defined here
/tmp/ccIvzb4o.o: In function `answer(int, int)':
grader.cpp:(.text+0x1e0): multiple definition of `answer(int, int)'
/tmp/ccBcvp20.o:highway.cpp:(.text+0x270): first defined here
/tmp/ccIvzb4o.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccBcvp20.o:highway.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status