#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
const int MAXN = 90000;
int n, m, tIn[MAXN], timer;
vector<int> u, v, adj[MAXN], adjTree[MAXN];
bool visited[MAXN];
long long allA;
void Dfs(int u, int p) {
tIn[u] = timer++;
for(int v : adjTree[u])
if (v != p)
Dfs(v, u);
}
void BuildTree(int s) {
for(int i = 0; i < n; i++){
adjTree[i].clear();
visited[i] = 0;
}
queue<int> qu;
visited[s] = 1;
qu.push(s);
while (!qu.empty()) {
int u = qu.front();
qu.pop();
for(int v : adj[u])
if (!visited[v]) {
visited[v] = 1;
qu.push(v);
adjTree[u].push_back(v);
adjTree[v].push_back(u);
}
}
timer = 0;
Dfs(s, -1);
}
long long MyAsk(int l, int r) {
vector<int> w(m);
for(int i = 0; i < m; i++)
if ((l <= tIn[u[i]] && tIn[u[i]] <= r) || (l <= tIn[v[i]] && tIn[v[i]] <= r))
w[i] = 1;
else
w[i] = 0;
return ask(w);
}
int Find_city() {
assert(timer == n);
int l = 0, r = n - 1, res = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (MyAsk(mid, n - 1) != allA) {
res = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
for(int i = 0; i < n; i++)
if (tIn[i] == res)
return i;
assert(0);
}
void find_pair(int _n, vector<int> _u, vector<int> _v, int a, int b) {
n = _n;
u = _u;
v = _v;
m = u.size();
for(int i = 0; i < m; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
iota(tIn, tIn + n, 0);
timer = n;
allA = MyAsk(-1, -1);
int root = Find_city();
BuildTree(root);
int s = Find_city();
BuildTree(s);
int t = Find_city();
answer(s, t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4424 KB |
Output is correct |
2 |
Correct |
4 ms |
4424 KB |
Output is correct |
3 |
Correct |
4 ms |
4424 KB |
Output is correct |
4 |
Correct |
3 ms |
4424 KB |
Output is correct |
5 |
Correct |
4 ms |
4536 KB |
Output is correct |
6 |
Correct |
4 ms |
4424 KB |
Output is correct |
7 |
Correct |
3 ms |
4536 KB |
Output is correct |
8 |
Correct |
4 ms |
4424 KB |
Output is correct |
9 |
Correct |
4 ms |
4424 KB |
Output is correct |
10 |
Correct |
3 ms |
4504 KB |
Output is correct |
11 |
Correct |
4 ms |
4424 KB |
Output is correct |
12 |
Correct |
3 ms |
4424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4552 KB |
Output is correct |
2 |
Correct |
19 ms |
5448 KB |
Output is correct |
3 |
Correct |
222 ms |
13360 KB |
Output is correct |
4 |
Correct |
205 ms |
13316 KB |
Output is correct |
5 |
Correct |
213 ms |
13324 KB |
Output is correct |
6 |
Correct |
260 ms |
13332 KB |
Output is correct |
7 |
Correct |
201 ms |
13308 KB |
Output is correct |
8 |
Correct |
180 ms |
13300 KB |
Output is correct |
9 |
Correct |
224 ms |
13308 KB |
Output is correct |
10 |
Correct |
234 ms |
13352 KB |
Output is correct |
11 |
Correct |
236 ms |
13556 KB |
Output is correct |
12 |
Correct |
211 ms |
13932 KB |
Output is correct |
13 |
Correct |
199 ms |
13596 KB |
Output is correct |
14 |
Correct |
221 ms |
13416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
5576 KB |
Output is correct |
2 |
Correct |
39 ms |
6740 KB |
Output is correct |
3 |
Correct |
59 ms |
7928 KB |
Output is correct |
4 |
Correct |
119 ms |
14396 KB |
Output is correct |
5 |
Correct |
160 ms |
14344 KB |
Output is correct |
6 |
Correct |
132 ms |
14824 KB |
Output is correct |
7 |
Correct |
119 ms |
15000 KB |
Output is correct |
8 |
Correct |
116 ms |
14564 KB |
Output is correct |
9 |
Correct |
169 ms |
14620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4552 KB |
Output is correct |
2 |
Correct |
24 ms |
5500 KB |
Output is correct |
3 |
Correct |
180 ms |
11376 KB |
Output is correct |
4 |
Correct |
225 ms |
13312 KB |
Output is correct |
5 |
Correct |
213 ms |
13348 KB |
Output is correct |
6 |
Correct |
171 ms |
13308 KB |
Output is correct |
7 |
Correct |
233 ms |
13324 KB |
Output is correct |
8 |
Correct |
221 ms |
13268 KB |
Output is correct |
9 |
Correct |
207 ms |
13332 KB |
Output is correct |
10 |
Correct |
237 ms |
13412 KB |
Output is correct |
11 |
Correct |
241 ms |
13424 KB |
Output is correct |
12 |
Correct |
205 ms |
13660 KB |
Output is correct |
13 |
Correct |
237 ms |
13532 KB |
Output is correct |
14 |
Correct |
248 ms |
13908 KB |
Output is correct |
15 |
Correct |
204 ms |
13504 KB |
Output is correct |
16 |
Correct |
228 ms |
13384 KB |
Output is correct |
17 |
Correct |
255 ms |
13568 KB |
Output is correct |
18 |
Correct |
243 ms |
13848 KB |
Output is correct |
19 |
Correct |
235 ms |
13320 KB |
Output is correct |
20 |
Correct |
215 ms |
13956 KB |
Output is correct |
21 |
Correct |
177 ms |
14152 KB |
Output is correct |
22 |
Correct |
153 ms |
14212 KB |
Output is correct |
23 |
Correct |
167 ms |
13980 KB |
Output is correct |
24 |
Correct |
186 ms |
14104 KB |
Output is correct |
25 |
Correct |
173 ms |
15048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
5436 KB |
Output is correct |
2 |
Correct |
24 ms |
5448 KB |
Output is correct |
3 |
Correct |
228 ms |
13876 KB |
Output is correct |
4 |
Correct |
289 ms |
14020 KB |
Output is correct |
5 |
Correct |
323 ms |
14696 KB |
Output is correct |
6 |
Correct |
304 ms |
14736 KB |
Output is correct |
7 |
Correct |
343 ms |
14720 KB |
Output is correct |
8 |
Correct |
289 ms |
14720 KB |
Output is correct |
9 |
Correct |
205 ms |
11476 KB |
Output is correct |
10 |
Correct |
268 ms |
11500 KB |
Output is correct |
11 |
Correct |
226 ms |
12600 KB |
Output is correct |
12 |
Correct |
336 ms |
13596 KB |
Output is correct |
13 |
Correct |
275 ms |
14108 KB |
Output is correct |
14 |
Correct |
327 ms |
14488 KB |
Output is correct |
15 |
Correct |
307 ms |
14448 KB |
Output is correct |
16 |
Correct |
265 ms |
11996 KB |
Output is correct |
17 |
Correct |
231 ms |
14304 KB |
Output is correct |
18 |
Correct |
192 ms |
14428 KB |
Output is correct |
19 |
Correct |
223 ms |
14300 KB |
Output is correct |
20 |
Correct |
198 ms |
14568 KB |
Output is correct |
21 |
Correct |
270 ms |
14516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5440 KB |
Output is correct |
2 |
Correct |
26 ms |
5548 KB |
Output is correct |
3 |
Correct |
277 ms |
13720 KB |
Output is correct |
4 |
Partially correct |
242 ms |
13940 KB |
Output is partially correct |
5 |
Partially correct |
306 ms |
14028 KB |
Output is partially correct |
6 |
Partially correct |
281 ms |
14732 KB |
Output is partially correct |
7 |
Correct |
282 ms |
13908 KB |
Output is correct |
8 |
Correct |
232 ms |
13944 KB |
Output is correct |
9 |
Correct |
282 ms |
14108 KB |
Output is correct |
10 |
Correct |
338 ms |
14724 KB |
Output is correct |
11 |
Partially correct |
340 ms |
14724 KB |
Output is partially correct |
12 |
Partially correct |
361 ms |
14716 KB |
Output is partially correct |
13 |
Correct |
280 ms |
12456 KB |
Output is correct |
14 |
Correct |
247 ms |
11364 KB |
Output is correct |
15 |
Correct |
251 ms |
11992 KB |
Output is correct |
16 |
Correct |
247 ms |
11480 KB |
Output is correct |
17 |
Correct |
295 ms |
12424 KB |
Output is correct |
18 |
Correct |
279 ms |
11452 KB |
Output is correct |
19 |
Correct |
253 ms |
13500 KB |
Output is correct |
20 |
Partially correct |
359 ms |
13896 KB |
Output is partially correct |
21 |
Partially correct |
338 ms |
14592 KB |
Output is partially correct |
22 |
Partially correct |
362 ms |
14396 KB |
Output is partially correct |
23 |
Correct |
300 ms |
14540 KB |
Output is correct |
24 |
Correct |
346 ms |
14532 KB |
Output is correct |
25 |
Partially correct |
354 ms |
14420 KB |
Output is partially correct |
26 |
Partially correct |
311 ms |
14552 KB |
Output is partially correct |
27 |
Correct |
170 ms |
14428 KB |
Output is correct |
28 |
Correct |
186 ms |
14276 KB |
Output is correct |
29 |
Correct |
175 ms |
14620 KB |
Output is correct |
30 |
Partially correct |
177 ms |
14472 KB |
Output is partially correct |
31 |
Partially correct |
166 ms |
14372 KB |
Output is partially correct |
32 |
Correct |
221 ms |
14288 KB |
Output is correct |
33 |
Partially correct |
210 ms |
14548 KB |
Output is partially correct |
34 |
Correct |
220 ms |
14428 KB |
Output is correct |
35 |
Partially correct |
206 ms |
14324 KB |
Output is partially correct |
36 |
Correct |
219 ms |
14284 KB |
Output is correct |
37 |
Partially correct |
215 ms |
14504 KB |
Output is partially correct |
38 |
Correct |
236 ms |
14440 KB |
Output is correct |
39 |
Partially correct |
281 ms |
14604 KB |
Output is partially correct |
40 |
Correct |
307 ms |
14708 KB |
Output is correct |
41 |
Partially correct |
294 ms |
14504 KB |
Output is partially correct |
42 |
Correct |
279 ms |
14488 KB |
Output is correct |