#include<bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
typedef vector <int> vi;
const int MAXN = 90005;
const int MAXM = 150005;
llint n, m, a, b, L, cnt;
int ea[MAXM], eb[MAXM], ok[MAXM];
int bio[MAXN], par[MAXN], pe[MAXN];
vector <pi> v[MAXN], nodes;
vector <int> nula, jen, edges, ch[MAXN];
queue <int> q;
llint pitaj (vi e) {
vi q(m);
for (auto i : e) q[i] = 1;
return ask(q);
}
llint get_length () {
vector <int> e;
return pitaj(e);
}
int find_edge (vi curr) {
int siz = curr.size();
if (siz == 1) return curr[0];
vi lo, hi;
for (int i = 0; i < siz; i++) {
if (2 * i < siz) lo.push_back(curr[i]); else hi.push_back(curr[i]);
}
edges.clear();
for (auto i : jen) edges.push_back(i);
for (auto i : lo) edges.push_back(i);
if (pitaj(edges) == L) {
for (auto i : lo) jen.push_back(i);
return find_edge(hi);
} else {
for (auto i : hi) nula.push_back(i);
return find_edge(lo);
}
}
void bfs (int ra, int rb) {
edges.clear();
memset(bio, -1, sizeof bio);
bio[ra] = bio[rb] = 0;
par[ra] = par[rb] = -1;
q.push(ra); q.push(rb);
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto pp : v[x]) {
int sus = pp.first, ind = pp.second;
if (bio[sus] == -1) {
ch[x].push_back(sus);
par[sus] = x;
pe[sus] = ind;
bio[sus] = 1 + bio[x];
q.push(sus);
}
}
}
for (int i = 0; i < n; i++) {
if (par[i] != -1) ok[pe[i]] = 1;
}
}
void dfs (int x, int rod) {
cnt++;
nodes.push_back({bio[x], x});
for (auto sus : ch[x]) {
dfs(sus, x);
}
}
int solve_subtree (int root, int rod) {
cnt = 0;
nodes.clear();
dfs(root, rod);
sort(nodes.begin(), nodes.end());
int lo = 0, hi = cnt - 1;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
edges.clear();
for (int i = 0; i < m; i++) {
if (!ok[i]) edges.push_back(i);
}
for (int i = mid; i < cnt; i++) {
int node = nodes[i].second;
edges.push_back(pe[node]);
}
if (pitaj(edges) > L) {
lo = mid;
} else {
hi = mid - 1;
}
}
return nodes[lo].second;
}
void find_pair (int N, vi U, vi V, int A, int B) {
n = N; m = U.size(), a = A, b = B;
for (int i = 0; i < m; i++) {
ea[i] = U[i], eb[i] = V[i];
v[U[i]].push_back({V[i], i});
v[V[i]].push_back({U[i], i});
}
L = get_length();
vi curr_edges;
for (int i = 0; i < m; i++) curr_edges.push_back(i);
int ind = find_edge(curr_edges);
ok[ind] = 1;
bfs(ea[ind], eb[ind]);
int sola = solve_subtree(ea[ind], eb[ind]);
int solb = solve_subtree(eb[ind], ea[ind]);
answer(sola, solb);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4864 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4888 KB |
Output is correct |
7 |
Correct |
4 ms |
4864 KB |
Output is correct |
8 |
Correct |
4 ms |
4864 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
21 ms |
6144 KB |
Output is correct |
3 |
Correct |
182 ms |
15884 KB |
Output is correct |
4 |
Correct |
188 ms |
15532 KB |
Output is correct |
5 |
Correct |
178 ms |
15628 KB |
Output is correct |
6 |
Correct |
172 ms |
15628 KB |
Output is correct |
7 |
Correct |
191 ms |
15772 KB |
Output is correct |
8 |
Correct |
185 ms |
15740 KB |
Output is correct |
9 |
Correct |
177 ms |
15796 KB |
Output is correct |
10 |
Correct |
178 ms |
15500 KB |
Output is correct |
11 |
Correct |
219 ms |
16628 KB |
Output is correct |
12 |
Correct |
213 ms |
17544 KB |
Output is correct |
13 |
Correct |
196 ms |
17332 KB |
Output is correct |
14 |
Correct |
197 ms |
17416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
6648 KB |
Output is correct |
2 |
Correct |
32 ms |
8168 KB |
Output is correct |
3 |
Correct |
54 ms |
9952 KB |
Output is correct |
4 |
Correct |
153 ms |
18536 KB |
Output is correct |
5 |
Correct |
149 ms |
18668 KB |
Output is correct |
6 |
Correct |
147 ms |
19340 KB |
Output is correct |
7 |
Correct |
162 ms |
20308 KB |
Output is correct |
8 |
Correct |
163 ms |
18860 KB |
Output is correct |
9 |
Correct |
243 ms |
19668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
25 ms |
6016 KB |
Output is correct |
3 |
Correct |
195 ms |
13796 KB |
Output is correct |
4 |
Correct |
288 ms |
15776 KB |
Output is correct |
5 |
Correct |
291 ms |
15940 KB |
Output is correct |
6 |
Correct |
281 ms |
15780 KB |
Output is correct |
7 |
Correct |
265 ms |
15880 KB |
Output is correct |
8 |
Correct |
179 ms |
16040 KB |
Output is correct |
9 |
Correct |
188 ms |
15496 KB |
Output is correct |
10 |
Correct |
241 ms |
15764 KB |
Output is correct |
11 |
Correct |
196 ms |
17532 KB |
Output is correct |
12 |
Correct |
204 ms |
17496 KB |
Output is correct |
13 |
Correct |
259 ms |
17676 KB |
Output is correct |
14 |
Correct |
259 ms |
16972 KB |
Output is correct |
15 |
Correct |
182 ms |
15860 KB |
Output is correct |
16 |
Correct |
182 ms |
16044 KB |
Output is correct |
17 |
Correct |
299 ms |
17288 KB |
Output is correct |
18 |
Correct |
187 ms |
17548 KB |
Output is correct |
19 |
Correct |
182 ms |
15952 KB |
Output is correct |
20 |
Correct |
198 ms |
18276 KB |
Output is correct |
21 |
Correct |
249 ms |
15724 KB |
Output is correct |
22 |
Correct |
164 ms |
16124 KB |
Output is correct |
23 |
Correct |
192 ms |
15060 KB |
Output is correct |
24 |
Correct |
167 ms |
15276 KB |
Output is correct |
25 |
Correct |
192 ms |
19552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
6272 KB |
Output is correct |
2 |
Correct |
24 ms |
6472 KB |
Output is correct |
3 |
Correct |
210 ms |
16244 KB |
Output is correct |
4 |
Correct |
240 ms |
17144 KB |
Output is correct |
5 |
Correct |
299 ms |
18560 KB |
Output is correct |
6 |
Correct |
293 ms |
17956 KB |
Output is correct |
7 |
Correct |
306 ms |
18168 KB |
Output is correct |
8 |
Correct |
286 ms |
18372 KB |
Output is correct |
9 |
Correct |
201 ms |
15476 KB |
Output is correct |
10 |
Correct |
203 ms |
17024 KB |
Output is correct |
11 |
Correct |
216 ms |
17112 KB |
Output is correct |
12 |
Correct |
271 ms |
17068 KB |
Output is correct |
13 |
Correct |
275 ms |
17772 KB |
Output is correct |
14 |
Correct |
292 ms |
18016 KB |
Output is correct |
15 |
Correct |
299 ms |
18488 KB |
Output is correct |
16 |
Correct |
244 ms |
16712 KB |
Output is correct |
17 |
Correct |
160 ms |
15628 KB |
Output is correct |
18 |
Correct |
170 ms |
15508 KB |
Output is correct |
19 |
Correct |
170 ms |
15704 KB |
Output is correct |
20 |
Correct |
168 ms |
15784 KB |
Output is correct |
21 |
Correct |
287 ms |
18864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
6264 KB |
Output is correct |
2 |
Correct |
23 ms |
6264 KB |
Output is correct |
3 |
Correct |
229 ms |
15692 KB |
Output is correct |
4 |
Correct |
248 ms |
16448 KB |
Output is correct |
5 |
Correct |
239 ms |
17252 KB |
Output is correct |
6 |
Correct |
287 ms |
18184 KB |
Output is correct |
7 |
Correct |
201 ms |
16484 KB |
Output is correct |
8 |
Correct |
225 ms |
16700 KB |
Output is correct |
9 |
Correct |
244 ms |
16892 KB |
Output is correct |
10 |
Correct |
283 ms |
18088 KB |
Output is correct |
11 |
Correct |
290 ms |
17992 KB |
Output is correct |
12 |
Correct |
286 ms |
17972 KB |
Output is correct |
13 |
Correct |
237 ms |
16620 KB |
Output is correct |
14 |
Correct |
210 ms |
15972 KB |
Output is correct |
15 |
Correct |
210 ms |
16884 KB |
Output is correct |
16 |
Correct |
200 ms |
17020 KB |
Output is correct |
17 |
Correct |
208 ms |
17024 KB |
Output is correct |
18 |
Correct |
197 ms |
17032 KB |
Output is correct |
19 |
Correct |
267 ms |
17616 KB |
Output is correct |
20 |
Correct |
283 ms |
17920 KB |
Output is correct |
21 |
Correct |
301 ms |
18104 KB |
Output is correct |
22 |
Correct |
298 ms |
17972 KB |
Output is correct |
23 |
Correct |
294 ms |
18364 KB |
Output is correct |
24 |
Correct |
294 ms |
17948 KB |
Output is correct |
25 |
Correct |
295 ms |
18916 KB |
Output is correct |
26 |
Correct |
283 ms |
18400 KB |
Output is correct |
27 |
Correct |
159 ms |
15872 KB |
Output is correct |
28 |
Correct |
163 ms |
15744 KB |
Output is correct |
29 |
Correct |
160 ms |
16000 KB |
Output is correct |
30 |
Correct |
166 ms |
16000 KB |
Output is correct |
31 |
Correct |
163 ms |
15760 KB |
Output is correct |
32 |
Correct |
166 ms |
15752 KB |
Output is correct |
33 |
Correct |
171 ms |
16000 KB |
Output is correct |
34 |
Correct |
176 ms |
15820 KB |
Output is correct |
35 |
Correct |
168 ms |
15840 KB |
Output is correct |
36 |
Correct |
165 ms |
15696 KB |
Output is correct |
37 |
Correct |
179 ms |
16036 KB |
Output is correct |
38 |
Correct |
168 ms |
15884 KB |
Output is correct |
39 |
Correct |
292 ms |
19048 KB |
Output is correct |
40 |
Correct |
292 ms |
19308 KB |
Output is correct |
41 |
Correct |
287 ms |
18704 KB |
Output is correct |
42 |
Correct |
295 ms |
18156 KB |
Output is correct |