#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = size(U), x = 0, u, d[2][N];
int64_t s = ask(vector<int> (M));
for(int b = 1<<17; b/=2; ) if(x + b < M) {
vector<int> w(M);
fill(begin(w), begin(w) + x + b, 1);
if(ask(w) == s) x |= b;
}
array<int, 2> S = {U[x], V[x]}, ans {};
vector<array<int, 2>> g[N];
vector<int> ord[2], a;
for(int i = x; i < M; i++) {
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i});
}
for(int k : {1, 0}) {
fill(d[k], d[k] + N, N);
queue<int> q;
d[k][S[k]] = 0;
q.push(S[k]);
while(!empty(q)) {
ord[k].push_back(u = q.front()); q.pop();
for(auto &[v, e] : g[u]) if(d[k][v] > d[k][u] + 1)
d[k][v] = d[k][u] + 1, q.push(v);
}
}
for(int k : {1, 0}) {
a.clear();
for(int i : ord[k])
if(d[k][i] < min(int(s / A), d[!k][i]) && (k || d[k][i] + d[!k][ans[1]] + 1 == s / A)) a.push_back(i);
for(int b = 1<<17; b/=2; ) if(ans[k] + b < size(a)) {
vector<int> w(M);
fill(begin(w), begin(w) + x, 1);
for(int i = ans[k] + b; --i >= 0; )
for(auto &[v, e] : g[a[size(a)-1-i]])
w[e] = 1;
if(ask(w) == s) ans[k] |= b;
}
ans[k] = a[size(a)-1-ans[k]];
}
answer(ans[0], ans[1]);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:42:44: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int b = 1<<17; b/=2; ) if(ans[k] + b < size(a)) {
# |
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 |
0 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 |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
14 ms |
1256 KB |
Output is correct |
3 |
Correct |
144 ms |
8944 KB |
Output is correct |
4 |
Correct |
184 ms |
9132 KB |
Output is correct |
5 |
Correct |
174 ms |
9468 KB |
Output is correct |
6 |
Correct |
145 ms |
9136 KB |
Output is correct |
7 |
Correct |
161 ms |
8860 KB |
Output is correct |
8 |
Correct |
161 ms |
9500 KB |
Output is correct |
9 |
Correct |
112 ms |
8784 KB |
Output is correct |
10 |
Correct |
119 ms |
9280 KB |
Output is correct |
11 |
Correct |
97 ms |
7820 KB |
Output is correct |
12 |
Correct |
129 ms |
8600 KB |
Output is correct |
13 |
Correct |
104 ms |
8640 KB |
Output is correct |
14 |
Correct |
108 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1080 KB |
Output is correct |
2 |
Correct |
18 ms |
1968 KB |
Output is correct |
3 |
Correct |
39 ms |
1948 KB |
Output is correct |
4 |
Correct |
110 ms |
7316 KB |
Output is correct |
5 |
Correct |
79 ms |
7348 KB |
Output is correct |
6 |
Correct |
87 ms |
8204 KB |
Output is correct |
7 |
Correct |
74 ms |
5156 KB |
Output is correct |
8 |
Correct |
75 ms |
7560 KB |
Output is correct |
9 |
Correct |
114 ms |
5924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
14 ms |
1200 KB |
Output is correct |
3 |
Correct |
91 ms |
7352 KB |
Output is correct |
4 |
Correct |
137 ms |
8884 KB |
Output is correct |
5 |
Correct |
82 ms |
7680 KB |
Output is correct |
6 |
Correct |
113 ms |
8024 KB |
Output is correct |
7 |
Correct |
125 ms |
8672 KB |
Output is correct |
8 |
Correct |
93 ms |
7948 KB |
Output is correct |
9 |
Correct |
117 ms |
8992 KB |
Output is correct |
10 |
Correct |
149 ms |
8932 KB |
Output is correct |
11 |
Correct |
136 ms |
8472 KB |
Output is correct |
12 |
Correct |
152 ms |
8820 KB |
Output is correct |
13 |
Correct |
121 ms |
8496 KB |
Output is correct |
14 |
Correct |
111 ms |
7972 KB |
Output is correct |
15 |
Correct |
84 ms |
7740 KB |
Output is correct |
16 |
Correct |
83 ms |
7252 KB |
Output is correct |
17 |
Correct |
93 ms |
8452 KB |
Output is correct |
18 |
Correct |
136 ms |
8556 KB |
Output is correct |
19 |
Correct |
86 ms |
7760 KB |
Output is correct |
20 |
Correct |
130 ms |
7720 KB |
Output is correct |
21 |
Correct |
128 ms |
8244 KB |
Output is correct |
22 |
Correct |
101 ms |
6292 KB |
Output is correct |
23 |
Correct |
123 ms |
9668 KB |
Output is correct |
24 |
Correct |
122 ms |
9696 KB |
Output is correct |
25 |
Correct |
133 ms |
8724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1388 KB |
Output is correct |
2 |
Correct |
14 ms |
1236 KB |
Output is correct |
3 |
Correct |
159 ms |
9856 KB |
Output is correct |
4 |
Correct |
134 ms |
9192 KB |
Output is correct |
5 |
Correct |
190 ms |
9668 KB |
Output is correct |
6 |
Correct |
251 ms |
11264 KB |
Output is correct |
7 |
Correct |
211 ms |
10164 KB |
Output is correct |
8 |
Correct |
170 ms |
9756 KB |
Output is correct |
9 |
Correct |
161 ms |
3892 KB |
Output is correct |
10 |
Correct |
109 ms |
4652 KB |
Output is correct |
11 |
Correct |
128 ms |
6612 KB |
Output is correct |
12 |
Correct |
207 ms |
9880 KB |
Output is correct |
13 |
Correct |
270 ms |
10592 KB |
Output is correct |
14 |
Correct |
232 ms |
10780 KB |
Output is correct |
15 |
Correct |
171 ms |
10764 KB |
Output is correct |
16 |
Correct |
211 ms |
8144 KB |
Output is correct |
17 |
Correct |
134 ms |
9244 KB |
Output is correct |
18 |
Correct |
118 ms |
7696 KB |
Output is correct |
19 |
Correct |
105 ms |
9244 KB |
Output is correct |
20 |
Correct |
108 ms |
8848 KB |
Output is correct |
21 |
Correct |
163 ms |
10868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1256 KB |
Output is correct |
2 |
Correct |
17 ms |
1360 KB |
Output is correct |
3 |
Correct |
182 ms |
9608 KB |
Output is correct |
4 |
Correct |
185 ms |
9560 KB |
Output is correct |
5 |
Correct |
230 ms |
9936 KB |
Output is correct |
6 |
Correct |
150 ms |
10284 KB |
Output is correct |
7 |
Correct |
175 ms |
9868 KB |
Output is correct |
8 |
Correct |
163 ms |
9860 KB |
Output is correct |
9 |
Correct |
177 ms |
9448 KB |
Output is correct |
10 |
Correct |
208 ms |
10400 KB |
Output is correct |
11 |
Correct |
226 ms |
10936 KB |
Output is correct |
12 |
Correct |
210 ms |
10416 KB |
Output is correct |
13 |
Correct |
108 ms |
4232 KB |
Output is correct |
14 |
Correct |
166 ms |
3596 KB |
Output is correct |
15 |
Correct |
117 ms |
7748 KB |
Output is correct |
16 |
Correct |
137 ms |
4664 KB |
Output is correct |
17 |
Correct |
187 ms |
6688 KB |
Output is correct |
18 |
Correct |
183 ms |
5560 KB |
Output is correct |
19 |
Correct |
167 ms |
9528 KB |
Output is correct |
20 |
Correct |
151 ms |
10260 KB |
Output is correct |
21 |
Correct |
266 ms |
10776 KB |
Output is correct |
22 |
Correct |
218 ms |
10580 KB |
Output is correct |
23 |
Correct |
235 ms |
11252 KB |
Output is correct |
24 |
Correct |
200 ms |
10912 KB |
Output is correct |
25 |
Correct |
138 ms |
10232 KB |
Output is correct |
26 |
Correct |
157 ms |
10728 KB |
Output is correct |
27 |
Correct |
142 ms |
8516 KB |
Output is correct |
28 |
Correct |
168 ms |
9152 KB |
Output is correct |
29 |
Correct |
180 ms |
9888 KB |
Output is correct |
30 |
Correct |
152 ms |
9524 KB |
Output is correct |
31 |
Correct |
163 ms |
9528 KB |
Output is correct |
32 |
Correct |
209 ms |
9300 KB |
Output is correct |
33 |
Correct |
135 ms |
9960 KB |
Output is correct |
34 |
Correct |
118 ms |
8968 KB |
Output is correct |
35 |
Correct |
123 ms |
8916 KB |
Output is correct |
36 |
Correct |
194 ms |
9472 KB |
Output is correct |
37 |
Correct |
207 ms |
9552 KB |
Output is correct |
38 |
Correct |
176 ms |
9404 KB |
Output is correct |
39 |
Correct |
201 ms |
10872 KB |
Output is correct |
40 |
Correct |
164 ms |
11072 KB |
Output is correct |
41 |
Correct |
169 ms |
11068 KB |
Output is correct |
42 |
Correct |
167 ms |
10872 KB |
Output is correct |