#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;
int find_hidden_node(const vector<vector<pair<int, int>>> &g, const int s, const int64 all_a, const vector<int> &template_w, const int a, const int b) {
const int n = g.size();
vector<int> w = template_w;
for (const auto &adj : g) {
for (const auto &[_, i] : adj) {
w[i] = 1;
}
}
vector<int> match(n, -1), rmatch(n, -1);
function<int(int, int, int)> postorder_traversal = [&](int x, int p, int v) {
for (const auto &[y, i] : g[x]) {
if (y == p) continue;
v = postorder_traversal(y, x, v) + 1;
}
match[x] = v;
rmatch[v] = x;
return v;
};
postorder_traversal(s, -1, 0);
function<void(int, int, int, int, int)> dfs = [&](const int x, const int p, const int idx, const int l, const int r) {
if (l <= match[x] and match[x] <= r) {
w[idx] = 1;
return;
}
for (const auto &[y, i] : g[x]) {
if (y == p) continue;
dfs(y, x, i, l, r);
}
};
w = template_w;
int lo = 0, hi = *max_element(match.begin(), match.end());
while (lo < hi) {
const int mid = (lo + hi) / 2;
dfs(s, -1, -1, lo, mid);
if (ask(w) > all_a) {
hi = mid;
} else {
lo = mid + 1;
}
w = template_w;
}
return rmatch[lo];
}
void find_pair(const int n, const vector<int> U, const vector<int> V, const int a, const int b) {
const int m = (int) U.size();
vector<int> w(m);
const int64 all_a = ask(w);
int lo = 0, hi = m - 1;
while (lo < hi) {
const int mid = (lo + hi) / 2;
for (int i = 0; i < m; i++) {
w[i] = (i <= mid);
}
if (ask(w) > all_a) {
hi = mid;
} else {
lo = mid + 1;
}
}
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
g[U[i]].emplace_back(V[i], i);
g[V[i]].emplace_back(U[i], i);
}
auto bfs = [&g](const int s) {
vector<int> dist(g.size(), kInf);
dist[s] = 0;
queue<int> q;
q.push(s);
while (not q.empty()) {
const int x = q.front();
for (const auto &[y, _] : g[x]) {
if (dist[y] < kInf) continue;
q.push(y);
dist[y] = dist[x] + 1;
}
q.pop();
}
return dist;
};
auto bfs_tree = [&](const int s, vector<int> near) -> vector<vector<pair<int, int>>> {
queue<int> q;
q.push(s);
vector<vector<pair<int, int>>> tree(n);
near[s] = 0;
while (not q.empty()) {
const int x = q.front();
for (const auto &[y, i] : g[x]) {
if (near[y] == 0) continue;
q.push(y);
tree[x].emplace_back(y, i);
near[y] = 0;
}
q.pop();
}
return tree;
};
const int x = U[lo], y = V[lo];
const vector<int> distx = bfs(x), disty = bfs(y);
vector<int> nearx(n), neary(n);
for (int i = 0; i < n; i++) {
nearx[i] = (distx[i] < disty[i]);
neary[i] = (disty[i] < distx[i]);
}
const auto tx = bfs_tree(x, nearx);
const auto ty = bfs_tree(y, neary);
vector<int> template_w(m, 1);
template_w[lo] = 0;
for (int u = 0; u < n; u++) {
for (const auto &[_, i] : tx[u]) {
template_w[i] = 0;
}
for (const auto &[_, i] : ty[u]) {
template_w[i] = 0;
}
}
const int s = find_hidden_node(tx, x, all_a, template_w, a, b);
const int t = find_hidden_node(ty, y, all_a, template_w, a, b);
answer(s, t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
14 ms |
2092 KB |
Output is correct |
3 |
Correct |
169 ms |
16284 KB |
Output is correct |
4 |
Correct |
178 ms |
16272 KB |
Output is correct |
5 |
Correct |
193 ms |
16232 KB |
Output is correct |
6 |
Correct |
168 ms |
16220 KB |
Output is correct |
7 |
Correct |
174 ms |
16284 KB |
Output is correct |
8 |
Correct |
185 ms |
16240 KB |
Output is correct |
9 |
Correct |
166 ms |
16248 KB |
Output is correct |
10 |
Correct |
204 ms |
16236 KB |
Output is correct |
11 |
Correct |
149 ms |
18764 KB |
Output is correct |
12 |
Correct |
190 ms |
19956 KB |
Output is correct |
13 |
Correct |
185 ms |
19292 KB |
Output is correct |
14 |
Correct |
186 ms |
19432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3076 KB |
Output is correct |
2 |
Correct |
23 ms |
5672 KB |
Output is correct |
3 |
Correct |
33 ms |
8644 KB |
Output is correct |
4 |
Correct |
107 ms |
22844 KB |
Output is correct |
5 |
Correct |
105 ms |
23044 KB |
Output is correct |
6 |
Correct |
120 ms |
24644 KB |
Output is correct |
7 |
Correct |
102 ms |
26096 KB |
Output is correct |
8 |
Correct |
128 ms |
23916 KB |
Output is correct |
9 |
Correct |
135 ms |
24080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
444 KB |
Output is correct |
2 |
Correct |
18 ms |
2068 KB |
Output is correct |
3 |
Correct |
148 ms |
12764 KB |
Output is correct |
4 |
Correct |
210 ms |
16236 KB |
Output is correct |
5 |
Correct |
180 ms |
16228 KB |
Output is correct |
6 |
Correct |
174 ms |
16232 KB |
Output is correct |
7 |
Correct |
165 ms |
16220 KB |
Output is correct |
8 |
Correct |
172 ms |
16232 KB |
Output is correct |
9 |
Correct |
193 ms |
16280 KB |
Output is correct |
10 |
Correct |
185 ms |
16348 KB |
Output is correct |
11 |
Correct |
183 ms |
18892 KB |
Output is correct |
12 |
Correct |
182 ms |
20036 KB |
Output is correct |
13 |
Correct |
183 ms |
19640 KB |
Output is correct |
14 |
Correct |
151 ms |
19500 KB |
Output is correct |
15 |
Correct |
163 ms |
16296 KB |
Output is correct |
16 |
Correct |
135 ms |
16236 KB |
Output is correct |
17 |
Correct |
214 ms |
19164 KB |
Output is correct |
18 |
Correct |
219 ms |
19716 KB |
Output is correct |
19 |
Correct |
151 ms |
16312 KB |
Output is correct |
20 |
Correct |
164 ms |
20472 KB |
Output is correct |
21 |
Correct |
126 ms |
15392 KB |
Output is correct |
22 |
Correct |
115 ms |
15464 KB |
Output is correct |
23 |
Correct |
131 ms |
15792 KB |
Output is correct |
24 |
Correct |
158 ms |
16272 KB |
Output is correct |
25 |
Correct |
197 ms |
25188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2032 KB |
Output is correct |
2 |
Correct |
17 ms |
2128 KB |
Output is correct |
3 |
Correct |
195 ms |
16704 KB |
Output is correct |
4 |
Correct |
255 ms |
17048 KB |
Output is correct |
5 |
Correct |
217 ms |
17900 KB |
Output is correct |
6 |
Correct |
250 ms |
17828 KB |
Output is correct |
7 |
Correct |
223 ms |
17692 KB |
Output is correct |
8 |
Correct |
208 ms |
17684 KB |
Output is correct |
9 |
Correct |
144 ms |
10044 KB |
Output is correct |
10 |
Correct |
178 ms |
9924 KB |
Output is correct |
11 |
Correct |
166 ms |
11760 KB |
Output is correct |
12 |
Correct |
256 ms |
15168 KB |
Output is correct |
13 |
Correct |
221 ms |
16424 KB |
Output is correct |
14 |
Correct |
270 ms |
17828 KB |
Output is correct |
15 |
Correct |
301 ms |
18060 KB |
Output is correct |
16 |
Correct |
204 ms |
11592 KB |
Output is correct |
17 |
Correct |
122 ms |
16052 KB |
Output is correct |
18 |
Correct |
160 ms |
16356 KB |
Output is correct |
19 |
Correct |
167 ms |
16200 KB |
Output is correct |
20 |
Correct |
126 ms |
16216 KB |
Output is correct |
21 |
Correct |
327 ms |
18896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2000 KB |
Output is correct |
2 |
Correct |
18 ms |
2164 KB |
Output is correct |
3 |
Correct |
185 ms |
16716 KB |
Output is correct |
4 |
Correct |
201 ms |
16700 KB |
Output is correct |
5 |
Correct |
251 ms |
16960 KB |
Output is correct |
6 |
Correct |
228 ms |
17692 KB |
Output is correct |
7 |
Correct |
177 ms |
16796 KB |
Output is correct |
8 |
Correct |
198 ms |
16880 KB |
Output is correct |
9 |
Correct |
192 ms |
16836 KB |
Output is correct |
10 |
Correct |
242 ms |
17808 KB |
Output is correct |
11 |
Correct |
233 ms |
17680 KB |
Output is correct |
12 |
Correct |
252 ms |
17688 KB |
Output is correct |
13 |
Correct |
146 ms |
11724 KB |
Output is correct |
14 |
Correct |
147 ms |
9940 KB |
Output is correct |
15 |
Correct |
195 ms |
11692 KB |
Output is correct |
16 |
Correct |
125 ms |
9920 KB |
Output is correct |
17 |
Correct |
161 ms |
11736 KB |
Output is correct |
18 |
Correct |
188 ms |
10000 KB |
Output is correct |
19 |
Correct |
243 ms |
15252 KB |
Output is correct |
20 |
Correct |
244 ms |
16824 KB |
Output is correct |
21 |
Correct |
295 ms |
17840 KB |
Output is correct |
22 |
Correct |
274 ms |
17828 KB |
Output is correct |
23 |
Correct |
289 ms |
17912 KB |
Output is correct |
24 |
Correct |
272 ms |
17836 KB |
Output is correct |
25 |
Correct |
287 ms |
17972 KB |
Output is correct |
26 |
Correct |
277 ms |
17864 KB |
Output is correct |
27 |
Correct |
157 ms |
16232 KB |
Output is correct |
28 |
Correct |
139 ms |
16056 KB |
Output is correct |
29 |
Correct |
127 ms |
16536 KB |
Output is correct |
30 |
Correct |
125 ms |
16240 KB |
Output is correct |
31 |
Correct |
163 ms |
16128 KB |
Output is correct |
32 |
Correct |
128 ms |
16016 KB |
Output is correct |
33 |
Correct |
121 ms |
16384 KB |
Output is correct |
34 |
Correct |
147 ms |
16212 KB |
Output is correct |
35 |
Correct |
130 ms |
16108 KB |
Output is correct |
36 |
Correct |
150 ms |
15952 KB |
Output is correct |
37 |
Correct |
132 ms |
16284 KB |
Output is correct |
38 |
Correct |
139 ms |
16316 KB |
Output is correct |
39 |
Correct |
252 ms |
19388 KB |
Output is correct |
40 |
Correct |
235 ms |
19884 KB |
Output is correct |
41 |
Correct |
308 ms |
18728 KB |
Output is correct |
42 |
Correct |
250 ms |
18612 KB |
Output is correct |