#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ask(const vector<int> &w);
void answer(int s, int t);
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
int m = u.size();
vector<int> w(m, 0);
ll dst = ask(w) / a;
vector<vector<int>> adj(n);
for (int i = 0; i < m; i++) {
adj[u[i]].push_back(i);
adj[v[i]].push_back(i);
}
int s;
{
queue<int> q;
vector<int> d(n, 1e9), p(n);
auto dfs = [&](auto &&dfs, int i, int par) -> void {
if (par != -1) p[i] = par;
for (int _j: adj[i]) {
if (_j == par) continue;
int j = u[_j] ^ v[_j] ^ i;
dfs(dfs, j, _j);
d[i] = min(d[i], d[j] + 1);
}
if (d[i] == 1e9) {
d[i] = 0;
}
}; dfs(dfs, 0, -1);
int mid = -1;
for (int k = 1 << 30; k; k >>= 1) {
if (mid + k >= d[0]) continue;
vector<int> ww(m);
for (int i = 0; i < n; i++) {
if (d[i] <= mid + k) ww[p[i]] = 1;
}
if (ask(ww) == dst) mid += k;
}
vector<int> check;
for (int i = 0; i < n; i++) {
if (d[i] == mid + 1) check.push_back(i);
}
while (check.size() > 1) {
for (auto &x: w) x = 0;
for (int i = 0; i < check.size(); i++) {
if (i & 1) {
w[p[check[i]]] = 1;
}
}
vector<int> cc;
int flag = ask(w) > a * dst;
for (auto i: check) {
if (w[p[i]] == flag) {
cc.push_back(i);
}
}
check = cc;
}
s = check[0];
}
vector<int> d(n, -1), check, p(n);
d[s] = 0;
queue<int> q; q.push(s);
while (!q.empty()) {
int i = q.front();
q.pop();
if (d[i] == dst) {
check.push_back(i);
continue;
}
for (int _j: adj[i]) {
int j = u[_j] ^ v[_j] ^ i;
if (d[j] == -1) {
p[j] = _j;
d[j] = d[i] + 1;
q.push(j);
}
}
}
while (check.size() > 1) {
for (auto &x: w) x = 0;
for (int i = 0; i < check.size(); i++) {
if (i & 1) {
w[p[check[i]]] = 1;
}
}
vector<int> cc;
int flag = ask(w) > a * dst;
for (auto i: check) {
if (w[p[i]] == flag) {
cc.push_back(i);
}
}
check = cc;
}
answer(s, check[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... |