# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
606616 | evenvalue | Combo (IOI18_combo) | C++17 | 0 ms | 0 KiB |
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;
void tree_subtask(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);
int64 all_0 = ask(w);
int lo = 0, hi = m - 1;
while (lo < hi) {
const int mid = (lo + hi) / 2;
fill(w.begin() + mid + 1, w.begin() + hi + 1, 1);
const int64 this_query = ask(w);
fill(w.begin() + mid + 1, w.begin() + hi + 1, 0);
if (this_query > all_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 find_s_t = [&](const int s, const int p) {
vector<int> w(m);
function<void(int, int)> dfs1 = [&](const int x, const int p) {
for (const auto &[y, i] : g[x]) {
if (y == p) continue;
w[i] = 1;
dfs1(y, x);
}
};
dfs1(s, p);
const int64 this_1 = ask(w);
const int depth = (this_1 - all_0) / (b - a);
if (depth == 0) {
return s;
}
vector<pair<int, int>> candidates;
function<void(int, int, int, int)> dfs2 = [&](const int x, const int par, const int d, const int idx) {
if (d == depth) {
candidates.emplace_back(x, idx);
return;
}
for (const auto &[y, i] : g[x]) {
if (y == par) continue;
dfs2(y, x, d + 1, i);
}
};
dfs2(s, p, 0, -1);
fill(w.begin(), w.end(), 0);
int lo = 0, hi = (int) 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) > all_0) {
hi = mid;
} else {
lo = mid + 1;
}
}
return candidates[lo].first;
};
answer(find_s_t(u[lo], v[lo]),
find_s_t(v[lo], u[lo]));
}
void find_pair(const int n, const vector<int> u, const vector<int> v, const int a, const int b) {
tree_subtask(n, u, v, a, b);
}