#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
inline void init_io() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
}
template <typename T>
vector<T> iota(int n, T x) {
vector<T> ans(n);
iota(begin(ans), end(ans), x);
return ans;
}
template <typename T>
vector<T>& operator+=(vector<T>& a, const vector<T>& b) {
a.insert(end(a), begin(b), end(b));
return a;
}
template <typename T>
vector<T> operator+(vector<T> a, const vector<T>& b) {
return a += b;
}
template <typename Cb>
struct CmpByKey {
Cb cb;
CmpByKey(Cb cb) : cb(cb) {}
template <typename T>
bool operator()(const T& a, const T& b) const {
return cb(a) < cb(b);
}
};
template <typename T, typename Cb>
T first_true(T l, T r, const Cb& cb) {
while (l < r) {
T mid = (l + r) / 2;
if (cb(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
template <typename T, typename Cb>
T last_true(T l, T r, const Cb& cb) {
while (l < r) {
T mid = (l + r + 1) / 2;
if (cb(mid)) {
l = mid;
} else {
r = mid - 1;
}
}
return l;
}
ll ask(const std::vector<int>& w);
void answer(int s, int t);
vector<int> bfs(const vector<vector<pair<int, int>>>& graph, int src) {
int n = sz(graph);
vector dist(n, -1);
queue<int> q;
auto push = [&](int u, int d) -> void {
if (dist[u] != -1) {
return;
}
dist[u] = d;
q.push(u);
};
push(src, 0);
while (sz(q)) {
int u = q.front();
q.pop();
for (auto& [v, _ei] : graph[u]) {
push(v, dist[u] + 1);
}
}
return dist;
}
void solve(int n, const vector<pair<int, int>>& edges, int wa, int wb) {
int m = sz(edges);
vector<vector<pair<int, int>>> graph(n);
for (int i = 0; i < m; i++) {
auto& [u, v] = edges[i];
graph[u].emplace_back(v, i);
graph[v].emplace_back(u, i);
}
long base = ask(vector<int>(m, 0));
auto nodes_blocked = [&](const vector<int>& nodes) -> vector<int> {
vector<int> cv(m);
for (auto& u : nodes) {
for (auto& [_v, ei] : graph[u]) {
cv[ei] = true;
}
}
return cv;
};
int root = first_true(0, n, [&](int x) -> bool {
return ask(nodes_blocked(iota(x + 1, 0))) > base;
});
auto base_block = iota(root, 0);
auto dist = bfs(graph, root);
auto ord = iota(n, 0);
sort(begin(ord), end(ord), CmpByKey([&](int u) -> int {
return dist[u];
}));
int u1_ind = last_true(0, n, [&](int x) -> bool {
return ask(nodes_blocked(vector(begin(ord) + x, end(ord))) +
base_block) > base;
});
int u2_ind = last_true(0, u1_ind, [&](int x) -> bool {
return ask(nodes_blocked(vector(begin(ord) + x, begin(ord) + u1_ind)) +
base_block) > base;
});
answer(ord[u1_ind], ord[u2_ind]);
}
void find_pair(int n,
vector<int> edges_u,
vector<int> edges_v,
int wa,
int wb) {
return solve(n, [&]() {
vector<pair<int, int>> cv;
for (int i = 0; i < n; i++) {
cv.emplace_back(edges_u[i], edges_v[i]);
}
return cv;
}(), wa, wb);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1112 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1112 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1112 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |