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>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
struct E {
int to, i;
};
const int N = 2e5 + 5;
vector<E> g[N];
int anc[N], d[N], pr[N], h[N];
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
int m = u.size();
for (int i = 0; i < m; i++) {
g[u[i]].push_back({v[i], i});
g[v[i]].push_back({u[i], i});
pr[i] = rand();
}
ll dist = ask(vector<int>(m, 0)) / a;
int l = -1, r = m - 1;
while (r - l > 1) {
int p = (l + r) >> 1;
vector<int> w(m, 0);
fill(w.begin(), w.begin() + p + 1, 1);
if (ask(w) != dist * a)
r = p;
else
l = p;
}
int rt[2] = {u[r], v[r]},
mid = r;
// cout << rt[0] << " " << rt[1] << "\n";
queue<int> q;
fill(d, d + n, -1);
d[rt[0]] = d[rt[1]] = 0;
h[rt[1]] = 1;
q.push(rt[0]);
q.push(rt[1]);
vector<int> half[2];
while (!q.empty()) {
int node = q.front();
q.pop();
for (E e : g[node]) {
if (d[e.to] == -1) {
d[e.to] = d[node] + 1;
h[e.to] = h[node];
anc[e.to] = e.i;
half[h[node]].push_back(e.i);
q.push(e.to);
}
}
}
for (int i = 0; i < m; i++) {
if (d[u[i]] > d[v[i]])
swap(u[i], v[i]);
}
for (int i = 0; i < 2; i++) {
sort(all(half[i]), [&](int x, int y) {
return d[v[x]] > d[v[y]];
});
}
// for (int i = 0; i < 2; i++) {
// for (int j : half[i]) {
// cout << u[j] << " " << v[j] << "\n";
// }
// cout << "\n";
// }
int ans[2];
for (int i = 0; i < 2; i++) {
int l = -1, r = half[i].size();
while (r - l > 1) {
int p = (l + r) >> 1;
vector<int> w(m, 1);
w[mid] = 0;
for (int j : half[i ^ 1])
w[j] = 0;
for (int j = p + 1; j < half[i].size(); j++) {
w[half[i][j]] = 0;
}
if (ask(w) != dist * a)
r = p;
else
l = p;
}
if (r == half[i].size())
ans[i] = rt[i];
else
ans[i] = v[half[i][r]];
}
// cout << ans[0] << " " << ans[1] << "\n";
answer(ans[0], ans[1]);
}
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:100:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = p + 1; j < half[i].size(); j++) {
~~^~~~~~~~~~~~~~~~
highway.cpp:110:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r == half[i].size())
~~^~~~~~~~~~~~~~~~~
# | 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... |