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>
int n, m;
std::vector <std::vector <int>> g;
long long dist;
void find_pair(int _n, std::vector <int> _u, std::vector <int> _v, int a, int b) {
n = _n;
m = _u.size();
g.resize(n);
for (int i = 0; i < m; i++) {
g[_u[i]].push_back(i);
g[_v[i]].push_back(i);
}
dist = ask(std::vector <int> (m, 0)) / a;
int root[2] = { -1, -1 };
int sec = -1;
{
int l = 0, r = m - 1, best = 0;
while (l <= r) {
int mid = (l + r) >> 1;
std::vector <int> cur(m, 1);
for (int i = 0; i <= mid; i++) {
cur[i] = 0;
}
long long val = ask(cur);
if (val != dist * a) {
best = mid + 1;
l = mid + 1;
} else {
r = mid - 1;
}
}
root[0] = _u[best];
root[1] = _v[best];
sec = best;
}
assert(root[0] != -1 && root[1] != -1);
assert(sec != -1);
std::vector <int> nod[2];
std::vector <int> par(n, -1);
{
std::queue <int> q;
q.push(root[0]);
q.push(root[1]);
std::vector <bool> vis(n, false);
std::vector <int> rof(n, -1);
rof[root[0]] = root[0];
rof[root[1]] = root[1];
nod[0].push_back(root[0]);
nod[1].push_back(root[1]);
vis[root[0]] = vis[root[1]] = true;
par[root[0]] = par[root[1]] = sec;
while (q.size()) {
int v = q.front(); q.pop();
for (int x : g[v]) {
int to = v ^ _u[x] ^ _v[x];
if (vis[to]) {
continue;
}
vis[to] = true;
rof[to] = rof[v];
nod[rof[v] == root[0] ? 0 : 1].push_back(to);
q.push(to);
par[to] = x;
}
}
}
int ans[2];
for (int i = 0; i <= 1; i++) {
int l = 0, r = (int) nod[i].size() - 1, best = nod[i][0];
while (l < r) {
int mid = (l + r) >> 1;
std::vector <int> cur(m, 1);
for (int x : nod[i ^ 1]) {
cur[par[x]] = 0;
}
for (int j = 0; j <= mid; j++) {
cur[par[nod[i][j]]] = 0;
}
long long val = ask(cur);
if (val > dist * a) {
best = nod[i][mid + 1];
l = mid + 1;
} else {
r = mid;
}
}
ans[i] = best;
}
answer(ans[0], ans[1]);
}
# | 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... |