이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
using ll = long long;
constexpr ll INF = 1000000000000000000LL;
ll n, m, q, k, x, y;
vector< pair<ll, ll> > G[90000];
vector<ll> ord;
ll par[90000];
vector<ll> dist[90000];
ll mxd = 0;
void dfs(ll x, ll p, ll d) {
par[x] = p;
for (auto i : G[x]) {
if (i.first != p) {
ord.push_back(i.second);
dist[d].push_back(i.second);
mxd = max(mxd, d);
dfs(i.first, x, d + 1);
}
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
map< pair<ll, ll>, ll > mp;
pair<ll, ll> p = {-1, -1};
n = N;
for (int i = 0; i < n - 1; i++) {
G[U[i]].push_back({V[i], i});
G[V[i]].push_back({U[i], i});
mp[{U[i], V[i]}] = i;
mp[{V[i], U[i]}] = i;
}
vector<int> w(n - 1, 1);
ll dst = ask(w) / B;
dfs(0, -1, 0);
for (int i = 0; i < n - 1; i++) {
if (par[U[i]] == V[i]) {
swap(U[i], V[i]);
}
}
ll l = 0, r = mxd;
while (r > l) {
ll mid = (r + l) / 2;
w.assign(n - 1, 0);
for (int i = 0; i <= mid; i++) {
for (int j : dist[i]) {
w[j] = 1;
}
}
if (ask(w) == dst * B) {
r = mid;
}
else {
l = mid + 1;
}
}
ll elow = l;
w.assign(n - 1, 0);
for (int i = 0; i <= l; i++) {
for (int j : dist[i]) {
w[j] = 1;
}
}
l = 0;
r = dist[elow].size() - 1;
while (r > l) {
ll mid = (r + l) / 2;
w.assign(n - 1, 0);
for (int i = 0; i <= mid; i++) {
w[dist[elow][i]] = 1;
}
// cout << mid << ' ' << dst * B << ' ' << ask(w) << ' ' << (B - A) << ' ' << (elow - mid + 1) << '\n';
if (ask(w) != dst * A) {
r = mid;
}
else {
l = mid + 1;
}
}
p.second = V[dist[elow][l]];
w.assign(n - 1, 0);
ll e = p.second;
while (e != 0) {
w[mp[{e, par[e]}]] = 1;
e = par[e];
}
if (ask(w) == dst * B) {
e = p.second;
for (int i = 0; i < dst; i++) {
e = par[e];
}
p.first = e;
answer(p.first, p.second);
return;
}
ord.clear();
for (int i = 0; i < mxd; i++) {
dist[i].clear();
}
mxd = 0;
dfs(p.second, -1, 0);
for (int i = 0; i < n - 1; i++) {
if (par[U[i]] == V[i]) {
swap(U[i], V[i]);
}
}
l = 0;
r = n - 1;
while (r > l) {
ll mid = (r + l) / 2;
w.assign(n - 1, 0);
for (int i = 0; i <= mid; i++) {
w[ord[i]] = 1;
}
if (ask(w) >= dst * B) {
r = mid;
}
else {
l = mid + 1;
}
}
p.first = V[ord[l]];
// cout << p.first << ' ' << p.second << '\n';
answer(p.first, p.second);
}
# | 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... |