이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
template <class F> int binary_search(int ok, int ng, int md, const F& f) {
while (abs(ok - ng) > 1) {
(f(md) ? ok : ng) = md;
md = (ok + ng) / 2;
}
return ok;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
const int M = (int)U.size();
vector<vector<int>> G(N);
for (int i = 0; i < M; ++i) {
G[U[i]].push_back(i);
G[V[i]].push_back(i);
}
vector<char> dead(N);
const auto bfs_order = [&](int src) {
vector<int> ret;
vector<char> done(N);
queue<int> que;
ret.reserve(N);
const auto push = [&](int u) {
if (!dead[u] && !done[u]) {
done[u] = true;
ret.push_back(u);
que.push(u);
}
};
push(src);
while (!que.empty()) {
const int u = que.front();
que.pop();
for (const int e : G[u]) {
push(u ^ U[e] ^ V[e]);
}
}
return ret;
};
const long long best = ask(vector(M, 0));
const int P = binary_search(0, N, N / 3, [&](int thres) {
vector<int> w(M);
for (int i = 0; i < thres; ++i) {
for (const int e : G[i]) w[e] = 1;
}
return ask(w) == best;
});
for (int i = 0; i < P; ++i) dead[i] = true;
const int S = [&] {
const auto ord = bfs_order(P);
const int n = (int)ord.size();
const int k = binary_search(n, 0, 2 * n / 3, [&](int thres) {
vector<int> w(M);
for (int i = thres; i < n; ++i) {
for (const int e : G[ord[i]]) w[e] = 1;
}
for (int i = 0; i < N; ++i) {
if (dead[i]) {
for (const int e : G[i]) w[e] = 1;
}
}
return ask(w) == best;
});
for (int i = k; i < n; ++i) dead[ord[i]] = true;
return ord[k - 1];
}();
const int T = [&] {
const auto ord = bfs_order(S);
const int n = (int)ord.size();
const int k = binary_search(n, 0, 2 * n / 3, [&](int thres) {
vector<int> w(M);
for (int i = thres; i < n; ++i) {
for (const int e : G[ord[i]]) w[e] = 1;
}
for (int i = 0; i < N; ++i) {
if (dead[i]) {
for (const int e : G[i]) w[e] = 1;
}
}
return ask(w) == best;
});
for (int i = k; i < n; ++i) dead[ord[i]] = true;
return ord[k - 1];
}();
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... |