#include "bits/stdc++.h"
#include "highway.h"
using namespace std;
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
int M = U.size();
vector<int> d(N), w(M);
int D = ask(w);
vector<vector<int>> g(N);
for (int i = 0; i < M; i++)
{
g[U[i]].push_back(V[i]);
g[V[i]].push_back(U[i]);
}
auto dfs = [&](auto dfs, int node, int par) -> void
{
for (auto &x : g[node])
{
if (x == par)
continue;
d[x] = d[node] + 1;
dfs(dfs, x, node);
}
};
dfs(dfs, 0, -1);
int a = 0;
int l = 0, r = N;
while (l <= r)
{
int m = (l + r) / 2;
for (int i = 0; i < M; i++)
w[i] = max(d[U[i]], d[V[i]]) > m;
int x = ask(w);
if (x == D)
r = m - 1;
else
a = m, l = m + 1;
}
vector<int> cands;
for (int i = 0; i < M; i++)
if (max(d[U[i]], d[V[i]]) == a)
cands.push_back(i);
while (cands.size() > 1)
{
int m = cands.size() / 2;
for (auto &i : w)
i = 0;
for (int j = 0; j < m; j++)
w[cands[j]] = 1;
int x = ask(w);
vector<int> R;
while (cands.size() > m)
R.push_back(cands.back()), cands.pop_back();
if (x == D)
cands = R;
}
answer(0, cands[0]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |