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;
using ll = long long;
#define sz(a) (int)a.size()
const int N = 90010;
vector<int> adj[N];
int depth[N], p[N];
void dfs(int u, int par) {
p[u] = par;
for(int v: adj[u]) {
if(v == par) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
}
}
bool what = false;
int find(int start, int n, vector<int> u, vector<int> v) {
map<pair<int, int>, int> idx;
for(int i = 0; i < N; ++i) {
adj[i].clear();
depth[i] = 0;
p[i] = -1;
}
int m = u.size();
for(int i = 0; i < m; ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
idx[{u[i], v[i]}] = idx[{v[i], u[i]}] = i;
}
dfs(start, -1);
int l = 1, r = n, dd = -1;
vector<int> c(m, 1);
int operations = 30;
while(operations > 0) {
ask(c);
--operations;
}
ll init = ask(c);
while(l <= r) {
int mid = l + r >> 1;
vector<int> now = c;
now.assign(m, 1);
for(int j = 0; j < n; ++j) {
if(depth[j] >= mid) {
now[idx[{j, p[j]}]] = 0;
}
}
if(ask(now) < init) {
dd = mid;
l = mid + 1;
} else r = mid - 1;
}
vector<int> nodes;
for(int i = 0; i < n; ++i) {
if(depth[i] == dd) nodes.push_back(i);
}
assert(sz(nodes) > 0);
l = 0, r = sz(nodes) - 1;
int pp = -1;
while(l <= r) {
int mid = l + r >> 1;
vector<int> now = c;
now.assign(m, 1);
for(int i = 0; i <= mid; ++i) {
assert(p[nodes[i]] != -1);
now[idx[{nodes[i], p[nodes[i]]}]] = 0;
}
if(ask(now) < init) {
pp = mid;
r = mid - 1;
} else l = mid + 1;
}
assert(pp != -1);
return nodes[pp];
}
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
int s = find(0, n, u, v);
what = true;
int t = find(s, n, u, v);
answer(t, s);
}
Compilation message (stderr)
highway.cpp: In function 'int find(int, int, std::vector<int>, std::vector<int>)':
highway.cpp:43:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
highway.cpp:65:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | int mid = l + r >> 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... |