#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);
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, -1);
for (int i = 0; i < n; i++) {
if (adj[i].size() == 1) {
d[i] = 0;
q.push(i);
}
}
while (!q.empty()) {
int i = q.front();
q.pop();
for (int _j: adj[i]) {
int j = u[_j] ^ v[_j] ^ i;
if (d[j] == -1) {
d[j] = d[i] + 1;
q.push(j);
}
}
}
int mad = *max_element(d.begin(), d.end());
int mid = -1;
for (int k = 1 << 30; k; k >>= 1) {
if (mid + k >= mad) continue;
vector<int> ww(m);
for (int i = 0; i < m; i++) {
if (d[u[i]] <= mid + k || d[v[i]] <= mid + k) ww[i] = 1;
}
if (ask(ww) == dst * a) 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) {
for (int _j: adj[check[i]]) {
w[_j] = 1;
}
}
}
vector<int> cc;
int flag = ask(w) > a * dst;
for (int i = 0; i < check.size(); i++) {
if (flag == i % 2) {
cc.push_back(check[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... |