This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
pair<int, int> subtask2(const int a, const int b, const vector<vector<pair<int, int>>> &g, const int s, const int p) {
const int m = accumulate(g.begin(), g.end(), 0, [](const int &v1, const vector<pair<int, int>> &v2) {
return v1 + v2.size();
}) / 2;
vector<int> w(m, 1);
const int64 d = ask(w);
function<void(int, int)> dfs1 = [&](const int x, const int p) {
for (const auto &[y, i] : g[x]) {
if (y == p) continue;
w[i] = 0;
dfs1(y, x);
}
};
dfs1(s, p);
const int64 c = ask(w);
const int depth = (c - d) / (a - b);
const int64 min_cost = (d / b) * a;
if (depth == 0) {
return {s, s};
}
vector<pair<int, int>> candidates;
function<void(int, int, int, int)> dfs = [&](const int x, const int p, const int d, const int idx) {
if (d == depth) {
candidates.emplace_back(x, idx);
return;
}
for (const auto &[y, i] : g[x]) {
if (y == p) continue;
dfs(y, x, d + 1, i);
}
};
dfs(s, p, 0, -1);
int lo = 0, hi = candidates.size() - 1;
while (lo < hi) {
const int mid = (lo + hi) / 2;
for (int i = lo; i <= mid; i++) {
w[candidates[i].second] = 1;
}
for (int i = mid + 1; i <= hi; i++) {
w[candidates[i].second] = 0;
}
if (ask(w) > min_cost) {
hi = mid;
} else {
lo = mid + 1;
}
}
return {s, candidates[lo].first};
}
void find_pair(const int n, const vector<int> u, const vector<int> v, const int a, const int b) {
const int m = u.size();
vector<int> w(m);
int all_0 = ask(w);
int lo = 0, hi = m - 1;
while (lo < hi) {
const int mid = (lo + hi) / 2;
fill(w.begin(), w.begin() + mid + 1, 0);
fill(w.begin() + mid + 1, w.begin() + hi + 1, 1);
const int this_query = ask(w);
if (this_query > all_0) {
fill(w.begin() + mid + 1, w.begin() + hi + 1, 0);
lo = mid + 1;
} else {
hi = mid;
}
}
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
const int x = u[i], y = v[i];
g[x].emplace_back(y, i);
g[y].emplace_back(x, i);
}
auto [_x, x] = subtask2(a, b, g, u[lo], v[lo]);
auto [_y, y] = subtask2(a, b, g, v[lo], u[lo]);
answer(x, y);
}
# | 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... |