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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
#include "highway.h"
int n, m, dis;
vector<int> edge[MAX_N];
vector<pair<int,int>> alle;
ll A, B;
ll qry(vector<int> ban_list) {
debug(AI(ban_list));
vector<int> ban(n);
for (int u : ban_list) ban[u] = true;
vector<int> w(m);
for (int i = 0;i < m;++i) {
auto [x, y] = alle[i];
w[i] = ban[x] || ban[y];
}
return ask(w);
}
void solve_tree_rt(int rt) {
vector<int> stk;
function<void(int,int)> dfs = [&](int x, int lst) {
stk.pb(x);
for (int u : edge[x]) if (u != lst)
dfs(u, x);
};
dfs(rt, rt);
int l = 0, r = n-1, mid;
while (l < r) {
mid = l + r >> 1;
ll v = qry( vector<int>(begin(stk), begin(stk)+mid ) );
ll more = (v - dis * A) / (B-A);
if (more < dis)
l = mid+1;
else
r = mid;
}
answer(rt, stk[l]);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
::A = A, ::B = B;
n = N, m = U.size();
assert(m == n-1);
for (int i = 0;i < m;++i) {
alle.pb(U[i], V[i]);
edge[U[i]].pb(V[i]);
edge[V[i]].pb(U[i]);
}
dis = qry( {} ) / A;
solve_tree_rt(0);
}
Compilation message (stderr)
highway.cpp: In function 'll qry(std::vector<int>)':
highway.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
highway.cpp:27:2: note: in expansion of macro 'debug'
27 | debug(AI(ban_list));
| ^~~~~
highway.cpp: In function 'void solve_tree_rt(int)':
highway.cpp:50:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | mid = l + r >> 1;
| ~~^~~
# | 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... |