이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e6;
vector<pii> g[N];
vector<int> s[N], h;
int n;
void bfs(int u) {
queue<int> q;
vector<int> d(n, -1);
d[u] = 0;
q.push(u);
while (sz(q)) {
int x = q.front();
s[d[x]].push_back(x);
q.pop();
for (auto [to, id]: g[x]) {
if (d[to] == -1) {
d[to] = d[x] + 1;
q.push(to);
}
}
}
}
void find_pair(int n1, vector<int> u, vector<int> v, int a, int b) {
n = n1;
for (int i = 0; i < sz(u); i++) {
g[u[i]].push_back({v[i], i});
g[v[i]].push_back({u[i], i});
}
vector<int> w(sz(u));
ll dt = ask(w);
int l = 0, r = sz(u) - 1;
while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) w[i] = 1;
if (ask(w) == dt) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) w[i] = 0;
}
int x = u[l], y = v[l];
bfs(y);
l = 0, r = n;
while (l <= r) {
int m = (l + r) / 2;
for (int i = m; i <= n; i++) {
for (int vt: s[i]) {
for (auto [to, id]: g[vt]) {
w[id] = 1;
}
}
}
if (ask(w) == dt) r = m - 1;
else l = m + 1;
for (int i = m; i <= n; i++) {
for (int vt: s[i]) {
for (auto [to, id]: g[vt]) {
w[id] = 0;
}
}
}
}
int z = r;
l = 0, r = sz(s[z]) - 1;
while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[s[z][i]]) {
w[id] = 1;
}
}
if (ask(w) == dt) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[s[z][i]]) {
w[id] = 0;
}
}
}
x = s[z][l];
dt /= a;
for (int i = 0; i <= n; i++) s[i].clear();
bfs(x);
h = s[dt];
l = 0, r = sz(h) - 1;
while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[h[i]]) w[id] = 1;
}
if (ask(w) == dt * 1ll * a) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[h[i]]) w[id] = 0;
}
}
answer(x, h[l]);
}
# | 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... |