#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
vector <int> G[101010], X, Y;
queue <int> Q;
int D1[101010], N1[101010], P1[101010];
int D2[101010], N2[101010], P2[101010];
int cnt;
void bfs(int p, int *D, int *N, int *P)
{
cnt = 0; Q.push(p);
N[p] = ++cnt;
for(; !Q.empty(); ){
p = Q.front(); Q.pop();
for(int &t: G[p]){
if(!N[t]){
P[t] = p; D[t] = D[p] + 1;
N[t] = ++cnt;
Q.push(t);
}
}
}
}
void find_pair(int n, vector <int> U, vector <int> V, int a, int b)
{
int m = U.size();
vector <int> W(m, 0);
int i, k, t, x, u, v, s, e;
for(i=0; i<m; i++){
G[U[i]].push_back(V[i]);
G[V[i]].push_back(U[i]);
}
k = ask(W) / a;
for(s=0, e=m-1; s<=e; ){
for(i=0; i<m; i++){
if(i <= (s + e >> 1)) W[i] = 1;
else W[i] = 0;
}
if(ask(W) != (ll)a * k) e = (s + e >> 1) - 1;
else s = (s + e >> 1) + 1;
}
t = e + 1;
bfs(U[t], D1, N1, P1);
bfs(V[t], D2, N2, P2);
for(i=0; i<n; i++){
if(D1[i] < D2[i]) X.push_back(i);
else if(D1[i] > D2[i]) Y.push_back(i);
}
sort(X.begin(), X.end(), [&](int &a, int &b){
return N1[a] < N1[b];
});
sort(Y.begin(), Y.end(), [&](int &a, int &b){
return N2[a] < N2[b];
});
for(s=0, e=X.size()-1; s<=e; ){
x = N1[X[s + e >> 1]];
for(i=0; i<m; i++){
if(i == t) W[i] = 0;
else if(D1[U[i]] < D2[U[i]] && D1[V[i]] < D2[V[i]]){
if(P1[U[i]] != V[i] && P1[V[i]] != U[i]) W[i] = 1;
else if(max(N1[U[i]], N1[V[i]]) > x) W[i] = 1;
else W[i] = 0;
}
else if(D1[U[i]] > D2[U[i]] && D1[V[i]] > D2[V[i]]) W[i] = 0;
else W[i] = 1;
}
if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
else e = (s + e >> 1) - 1;
}
u = X[e + 1];
for(s=0, e=Y.size()-1; s<=e; ){
x = N2[Y[s + e >> 1]];
for(i=0; i<m; i++){
if(i == t) W[i] = 0;
else if(D2[U[i]] < D1[U[i]] && D2[V[i]] < D1[V[i]]){
if(P2[U[i]] != V[i] && P2[V[i]] != U[i]) W[i] = 1;
else if(max(N2[U[i]], N2[V[i]]) > x) W[i] = 1;
else W[i] = 0;
}
else if(D2[U[i]] > D1[U[i]] && D2[V[i]] > D1[V[i]]) W[i] = 0;
else W[i] = 1;
}
if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
else e = (s + e >> 1) - 1;
}
v = Y[e + 1];
answer(u, v);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(i <= (s + e >> 1)) W[i] = 1;
~~^~~
highway.cpp:49:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(ask(W) != (ll)a * k) e = (s + e >> 1) - 1;
~~^~~
highway.cpp:50:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else s = (s + e >> 1) + 1;
~~^~~
highway.cpp:71:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
x = N1[X[s + e >> 1]];
~~^~~
highway.cpp:82:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
~~^~~
highway.cpp:83:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else e = (s + e >> 1) - 1;
~~^~~
highway.cpp:89:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
x = N2[Y[s + e >> 1]];
~~^~~
highway.cpp:100:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(ask(W) != (ll)a * k) s = (s + e >> 1) + 1;
~~^~~
highway.cpp:101:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else e = (s + e >> 1) - 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2708 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2704 KB |
Output is correct |
4 |
Correct |
4 ms |
2728 KB |
Output is correct |
5 |
Correct |
4 ms |
2696 KB |
Output is correct |
6 |
Correct |
4 ms |
2700 KB |
Output is correct |
7 |
Correct |
4 ms |
2700 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2696 KB |
Output is correct |
11 |
Correct |
4 ms |
2704 KB |
Output is correct |
12 |
Correct |
4 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2744 KB |
Output is correct |
2 |
Correct |
26 ms |
3472 KB |
Output is correct |
3 |
Correct |
249 ms |
10084 KB |
Output is correct |
4 |
Correct |
273 ms |
10124 KB |
Output is correct |
5 |
Correct |
249 ms |
10080 KB |
Output is correct |
6 |
Correct |
250 ms |
10068 KB |
Output is correct |
7 |
Correct |
294 ms |
10120 KB |
Output is correct |
8 |
Correct |
249 ms |
10076 KB |
Output is correct |
9 |
Correct |
245 ms |
10072 KB |
Output is correct |
10 |
Correct |
265 ms |
10128 KB |
Output is correct |
11 |
Correct |
315 ms |
10004 KB |
Output is correct |
12 |
Correct |
304 ms |
10096 KB |
Output is correct |
13 |
Correct |
304 ms |
10016 KB |
Output is correct |
14 |
Correct |
282 ms |
9972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3576 KB |
Output is correct |
2 |
Correct |
26 ms |
4340 KB |
Output is correct |
3 |
Correct |
61 ms |
5200 KB |
Output is correct |
4 |
Correct |
190 ms |
9900 KB |
Output is correct |
5 |
Correct |
188 ms |
9928 KB |
Output is correct |
6 |
Correct |
188 ms |
10112 KB |
Output is correct |
7 |
Correct |
189 ms |
9972 KB |
Output is correct |
8 |
Correct |
175 ms |
9896 KB |
Output is correct |
9 |
Correct |
167 ms |
9972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2832 KB |
Output is correct |
2 |
Correct |
32 ms |
3536 KB |
Output is correct |
3 |
Correct |
192 ms |
8612 KB |
Output is correct |
4 |
Correct |
247 ms |
10080 KB |
Output is correct |
5 |
Correct |
260 ms |
10056 KB |
Output is correct |
6 |
Correct |
278 ms |
10044 KB |
Output is correct |
7 |
Correct |
246 ms |
10092 KB |
Output is correct |
8 |
Correct |
241 ms |
10076 KB |
Output is correct |
9 |
Correct |
268 ms |
10116 KB |
Output is correct |
10 |
Correct |
303 ms |
10072 KB |
Output is correct |
11 |
Correct |
266 ms |
9972 KB |
Output is correct |
12 |
Correct |
282 ms |
9976 KB |
Output is correct |
13 |
Correct |
314 ms |
10140 KB |
Output is correct |
14 |
Correct |
300 ms |
9916 KB |
Output is correct |
15 |
Correct |
252 ms |
10268 KB |
Output is correct |
16 |
Correct |
239 ms |
10112 KB |
Output is correct |
17 |
Correct |
296 ms |
10100 KB |
Output is correct |
18 |
Correct |
278 ms |
9972 KB |
Output is correct |
19 |
Correct |
250 ms |
10128 KB |
Output is correct |
20 |
Correct |
246 ms |
10008 KB |
Output is correct |
21 |
Correct |
198 ms |
10760 KB |
Output is correct |
22 |
Correct |
232 ms |
10756 KB |
Output is correct |
23 |
Correct |
251 ms |
10692 KB |
Output is correct |
24 |
Correct |
268 ms |
10440 KB |
Output is correct |
25 |
Correct |
280 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3488 KB |
Output is correct |
2 |
Correct |
34 ms |
3616 KB |
Output is correct |
3 |
Correct |
291 ms |
10300 KB |
Output is correct |
4 |
Correct |
358 ms |
10596 KB |
Output is correct |
5 |
Correct |
378 ms |
11232 KB |
Output is correct |
6 |
Correct |
398 ms |
11060 KB |
Output is correct |
7 |
Correct |
403 ms |
11104 KB |
Output is correct |
8 |
Correct |
414 ms |
11052 KB |
Output is correct |
9 |
Correct |
292 ms |
7916 KB |
Output is correct |
10 |
Correct |
305 ms |
8236 KB |
Output is correct |
11 |
Correct |
315 ms |
8596 KB |
Output is correct |
12 |
Correct |
431 ms |
10124 KB |
Output is correct |
13 |
Correct |
431 ms |
10604 KB |
Output is correct |
14 |
Correct |
458 ms |
10932 KB |
Output is correct |
15 |
Correct |
380 ms |
10924 KB |
Output is correct |
16 |
Correct |
371 ms |
8720 KB |
Output is correct |
17 |
Correct |
199 ms |
10636 KB |
Output is correct |
18 |
Correct |
240 ms |
10792 KB |
Output is correct |
19 |
Correct |
240 ms |
10624 KB |
Output is correct |
20 |
Correct |
263 ms |
10768 KB |
Output is correct |
21 |
Correct |
380 ms |
10984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3488 KB |
Output is correct |
2 |
Correct |
33 ms |
3624 KB |
Output is correct |
3 |
Correct |
330 ms |
10344 KB |
Output is correct |
4 |
Correct |
345 ms |
10348 KB |
Output is correct |
5 |
Correct |
348 ms |
10548 KB |
Output is correct |
6 |
Correct |
384 ms |
10972 KB |
Output is correct |
7 |
Correct |
267 ms |
10320 KB |
Output is correct |
8 |
Correct |
307 ms |
10460 KB |
Output is correct |
9 |
Correct |
316 ms |
10612 KB |
Output is correct |
10 |
Correct |
424 ms |
10992 KB |
Output is correct |
11 |
Correct |
402 ms |
11048 KB |
Output is correct |
12 |
Correct |
405 ms |
11080 KB |
Output is correct |
13 |
Correct |
296 ms |
8620 KB |
Output is correct |
14 |
Correct |
279 ms |
8160 KB |
Output is correct |
15 |
Correct |
302 ms |
8692 KB |
Output is correct |
16 |
Correct |
276 ms |
8384 KB |
Output is correct |
17 |
Correct |
303 ms |
8612 KB |
Output is correct |
18 |
Correct |
292 ms |
8188 KB |
Output is correct |
19 |
Correct |
392 ms |
10192 KB |
Output is correct |
20 |
Correct |
383 ms |
10444 KB |
Output is correct |
21 |
Correct |
422 ms |
10864 KB |
Output is correct |
22 |
Correct |
425 ms |
10936 KB |
Output is correct |
23 |
Correct |
414 ms |
10884 KB |
Output is correct |
24 |
Correct |
453 ms |
10876 KB |
Output is correct |
25 |
Correct |
443 ms |
10872 KB |
Output is correct |
26 |
Correct |
405 ms |
10952 KB |
Output is correct |
27 |
Correct |
244 ms |
10736 KB |
Output is correct |
28 |
Correct |
252 ms |
10668 KB |
Output is correct |
29 |
Correct |
219 ms |
10824 KB |
Output is correct |
30 |
Correct |
239 ms |
10720 KB |
Output is correct |
31 |
Correct |
237 ms |
10712 KB |
Output is correct |
32 |
Correct |
260 ms |
10636 KB |
Output is correct |
33 |
Correct |
252 ms |
10912 KB |
Output is correct |
34 |
Correct |
263 ms |
10752 KB |
Output is correct |
35 |
Correct |
271 ms |
10656 KB |
Output is correct |
36 |
Correct |
220 ms |
10624 KB |
Output is correct |
37 |
Correct |
248 ms |
10888 KB |
Output is correct |
38 |
Correct |
242 ms |
10768 KB |
Output is correct |
39 |
Correct |
380 ms |
10988 KB |
Output is correct |
40 |
Correct |
388 ms |
10964 KB |
Output is correct |
41 |
Correct |
364 ms |
11032 KB |
Output is correct |
42 |
Correct |
402 ms |
10940 KB |
Output is correct |