#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
void find_pair(int N, vector<int> U,
vector<int> V, int A, int B) {
int M = U.size();
int lo = 0, hi = M - 1;
vector<int> w(M);
long long init = ask(w);
int root[2], ans[2];
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int i = 0; i < M; i++)
w[i] = i <= mi;
if (ask(w) > init) {
root[0] = U[mi];
root[1] = V[mi];
hi = mi - 1;
} else lo = mi + 1;
}
vector<vector<int>> adj(N);
for (int i = 0; i < M; i++) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
vector<int> dis[2], vis[2];
queue<int> que;
for (int i = 0; i < 2; i++) {
dis[i].assign(N, -1);
vis[i].resize(N);
que.push(root[i]);
dis[i][root[i]] = 0;
ans[i] = root[i];
while (que.size()) {
int u = que.front(); que.pop();
for (int e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (dis[i][v] < 0) {
dis[i][v] = dis[i][u] + 1;
que.push(v);
}
}
}
}
vector<int> ord, idx(N);
for (int i = 0; i < 2; i++) {
que.push(root[i]);
vis[i][root[i]] = 1;
ord.assign(M, -1);
int cnt = 0;
while (que.size()) {
int u = que.front(); que.pop();
for (int e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (dis[i][v] < dis[i ^ 1][v]) {
if (!vis[i][v]) {
idx[ord[e] = cnt++] = e;
vis[i][v] = 1; que.push(v);
} else if (dis[i][v] == dis[i][u] + 1)
ord[e] = N;
} else if (root[0] != U[e] || root[1] != V[e])
ord[e] = N;
}
}
lo = 0; hi = cnt - 1;
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int j = 0; j < M; j++)
w[j] = ord[j] >= mi;
if (ask(w) > init) {
int e = idx[mi];
if (dis[i][U[e]] > dis[i][V[e]])
ans[i] = U[e];
else ans[i] = V[e];
lo = mi + 1;
} else hi = mi - 1;
}
}
answer(ans[0], ans[1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
16 ms |
1280 KB |
Output is correct |
3 |
Correct |
153 ms |
9292 KB |
Output is correct |
4 |
Correct |
154 ms |
9476 KB |
Output is correct |
5 |
Correct |
196 ms |
9252 KB |
Output is correct |
6 |
Correct |
188 ms |
9248 KB |
Output is correct |
7 |
Correct |
164 ms |
9452 KB |
Output is correct |
8 |
Correct |
142 ms |
9268 KB |
Output is correct |
9 |
Correct |
186 ms |
9288 KB |
Output is correct |
10 |
Correct |
149 ms |
9244 KB |
Output is correct |
11 |
Correct |
218 ms |
9324 KB |
Output is correct |
12 |
Correct |
167 ms |
9204 KB |
Output is correct |
13 |
Correct |
169 ms |
9100 KB |
Output is correct |
14 |
Correct |
150 ms |
9104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1252 KB |
Output is correct |
2 |
Correct |
29 ms |
2244 KB |
Output is correct |
3 |
Correct |
41 ms |
3236 KB |
Output is correct |
4 |
Correct |
154 ms |
9264 KB |
Output is correct |
5 |
Correct |
159 ms |
9100 KB |
Output is correct |
6 |
Correct |
161 ms |
9096 KB |
Output is correct |
7 |
Correct |
137 ms |
9116 KB |
Output is correct |
8 |
Correct |
155 ms |
9100 KB |
Output is correct |
9 |
Correct |
152 ms |
9108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
21 ms |
1240 KB |
Output is correct |
3 |
Correct |
108 ms |
7292 KB |
Output is correct |
4 |
Correct |
190 ms |
9240 KB |
Output is correct |
5 |
Correct |
141 ms |
9376 KB |
Output is correct |
6 |
Correct |
136 ms |
9252 KB |
Output is correct |
7 |
Correct |
143 ms |
9344 KB |
Output is correct |
8 |
Correct |
159 ms |
9236 KB |
Output is correct |
9 |
Correct |
208 ms |
9344 KB |
Output is correct |
10 |
Correct |
210 ms |
9248 KB |
Output is correct |
11 |
Correct |
163 ms |
9108 KB |
Output is correct |
12 |
Correct |
197 ms |
9096 KB |
Output is correct |
13 |
Correct |
203 ms |
9304 KB |
Output is correct |
14 |
Correct |
206 ms |
9104 KB |
Output is correct |
15 |
Correct |
193 ms |
9264 KB |
Output is correct |
16 |
Correct |
203 ms |
9260 KB |
Output is correct |
17 |
Correct |
162 ms |
9116 KB |
Output is correct |
18 |
Correct |
210 ms |
9100 KB |
Output is correct |
19 |
Correct |
186 ms |
9256 KB |
Output is correct |
20 |
Correct |
243 ms |
9156 KB |
Output is correct |
21 |
Correct |
152 ms |
9844 KB |
Output is correct |
22 |
Correct |
136 ms |
9864 KB |
Output is correct |
23 |
Correct |
166 ms |
9644 KB |
Output is correct |
24 |
Correct |
175 ms |
9644 KB |
Output is correct |
25 |
Correct |
143 ms |
9168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1268 KB |
Output is correct |
2 |
Correct |
23 ms |
1216 KB |
Output is correct |
3 |
Correct |
216 ms |
9556 KB |
Output is correct |
4 |
Correct |
185 ms |
9912 KB |
Output is correct |
5 |
Correct |
286 ms |
10440 KB |
Output is correct |
6 |
Correct |
282 ms |
10504 KB |
Output is correct |
7 |
Correct |
224 ms |
10632 KB |
Output is correct |
8 |
Correct |
236 ms |
10512 KB |
Output is correct |
9 |
Correct |
213 ms |
6480 KB |
Output is correct |
10 |
Correct |
151 ms |
6588 KB |
Output is correct |
11 |
Correct |
227 ms |
7312 KB |
Output is correct |
12 |
Correct |
253 ms |
9288 KB |
Output is correct |
13 |
Correct |
274 ms |
9872 KB |
Output is correct |
14 |
Correct |
292 ms |
10404 KB |
Output is correct |
15 |
Correct |
213 ms |
10300 KB |
Output is correct |
16 |
Correct |
176 ms |
7500 KB |
Output is correct |
17 |
Correct |
143 ms |
9908 KB |
Output is correct |
18 |
Correct |
180 ms |
10060 KB |
Output is correct |
19 |
Correct |
150 ms |
9932 KB |
Output is correct |
20 |
Correct |
131 ms |
10148 KB |
Output is correct |
21 |
Correct |
274 ms |
10292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1344 KB |
Output is correct |
2 |
Correct |
22 ms |
1260 KB |
Output is correct |
3 |
Correct |
191 ms |
9724 KB |
Output is correct |
4 |
Correct |
229 ms |
9700 KB |
Output is correct |
5 |
Correct |
244 ms |
9836 KB |
Output is correct |
6 |
Correct |
244 ms |
10440 KB |
Output is correct |
7 |
Correct |
188 ms |
9580 KB |
Output is correct |
8 |
Correct |
221 ms |
9700 KB |
Output is correct |
9 |
Correct |
244 ms |
9836 KB |
Output is correct |
10 |
Correct |
263 ms |
10448 KB |
Output is correct |
11 |
Correct |
221 ms |
10452 KB |
Output is correct |
12 |
Correct |
279 ms |
10460 KB |
Output is correct |
13 |
Correct |
217 ms |
7324 KB |
Output is correct |
14 |
Correct |
150 ms |
6704 KB |
Output is correct |
15 |
Correct |
224 ms |
7312 KB |
Output is correct |
16 |
Correct |
168 ms |
6616 KB |
Output is correct |
17 |
Correct |
225 ms |
7312 KB |
Output is correct |
18 |
Correct |
154 ms |
6596 KB |
Output is correct |
19 |
Correct |
269 ms |
9292 KB |
Output is correct |
20 |
Correct |
206 ms |
9752 KB |
Output is correct |
21 |
Correct |
284 ms |
10292 KB |
Output is correct |
22 |
Correct |
289 ms |
10268 KB |
Output is correct |
23 |
Correct |
233 ms |
10408 KB |
Output is correct |
24 |
Correct |
284 ms |
10292 KB |
Output is correct |
25 |
Correct |
280 ms |
10296 KB |
Output is correct |
26 |
Correct |
286 ms |
10308 KB |
Output is correct |
27 |
Correct |
140 ms |
10048 KB |
Output is correct |
28 |
Correct |
178 ms |
9940 KB |
Output is correct |
29 |
Correct |
128 ms |
10148 KB |
Output is correct |
30 |
Correct |
173 ms |
9960 KB |
Output is correct |
31 |
Correct |
165 ms |
9988 KB |
Output is correct |
32 |
Correct |
136 ms |
9864 KB |
Output is correct |
33 |
Correct |
181 ms |
10064 KB |
Output is correct |
34 |
Correct |
131 ms |
9940 KB |
Output is correct |
35 |
Correct |
133 ms |
10044 KB |
Output is correct |
36 |
Correct |
179 ms |
9876 KB |
Output is correct |
37 |
Correct |
134 ms |
10140 KB |
Output is correct |
38 |
Correct |
135 ms |
9972 KB |
Output is correct |
39 |
Correct |
264 ms |
10272 KB |
Output is correct |
40 |
Correct |
269 ms |
10356 KB |
Output is correct |
41 |
Correct |
246 ms |
10288 KB |
Output is correct |
42 |
Correct |
213 ms |
10284 KB |
Output is correct |