이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "highway.h"
#define fi first
#define se second
#define p_b push_back
#define m_p make_pair
#define sz(x) (int)x.size()
#define pii pair <int, int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
vector < vector <pii> > v;
vector <int> p, tin, tout, nm, order, deep;
vector <vector <int> > level;
int _timer;
void dfs(int x, int pr, int gl){
p[x] = pr;
tin[x] = ++_timer;
order.p_b(x);
deep[x] = gl;
level[gl].p_b(x);
for(auto to : v[x])if(to.fi != pr){
dfs(to.fi, x, gl + 1);
nm[to.fi] = to.se;
}
tout[x] = _timer;
}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
int m = U.size();
_timer = 0;
tin.resize(n);
tout.resize(n);
p.resize(n);
v.resize(n);
nm.resize(n);
deep.resize(n);
level.resize(n);
vector <int> w(m, 0);
ll dist = ask(w);
ll Len = dist / A;
for(int i = 0; i < m; i++){
v[U[i]].p_b({V[i], i});
v[V[i]].p_b({U[i], i});
}
dfs(0, -1, 0);
int Lca = -1;
int l = 0, r = n - 1;
while(l < r){
int mid = (l + r) >> 1;
fill(all(w), 0);
for(int i = 0; i <= mid; i++){
for(auto j : v[order[i]])if(j.fi != p[order[i]])w[j.se] = 1;
}
if(ask(w) == dist)l = mid + 1;
else r = mid;
}
Lca = order[l];
l = 0, r = n;
while(l < r){
int mid = (l + r) >> 1;
fill(all(w), 0);
for(int i = mid + 1; i < n; i++)w[nm[order[i]]] = 1;
if(ask(w) != dist)l = mid + 1;
else r = mid;
}
int S = order[l];
int T = -1;
int ost = Len - (deep[S] - deep[Lca]);
vector <int> mb;
for(int i : level[ost + deep[Lca]]){
if(tin[Lca] <= tin[i] && tout[i] <= tout[Lca])mb.p_b(i);
}
l = 0, r = sz(mb) - 1;
while(l < r){
int mid = (l + r) >> 1;
fill(all(w), 0);
for(int i = 1; i < tin[mb[mid]]; i++)w[nm[order[i]]] = 1;;
if(ask(w) < dist + ost * (B - A))l = mid + 1;
else r = mid;
}
T = mb[l];
answer(S, T);
}
# | 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... |