#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
using ll = long long;
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];
ll least = 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) == least) x |= b;
}
array<int, 2> S = {U[x], V[x]}, ans {};
vector<array<int, 2>> g[N], 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 : {0, 1}) {
fill(d[k], d[k] + N, N);
queue<int> q;
d[k][S[k]] = 0;
q.push(S[k]);
while(!empty(q)) {
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 : {0, 1}) {
a.clear();
for(int i = 0; i < N; i++)
if(d[k][i] < d[!k][i]) a.push_back({-d[k][i], i});
sort(begin(a), end(a));
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[i][1]])
w[e] = 1;
if(ask(w) == least) ans[k] |= b;
}
ans[k] = a[ans[k]][1];
}
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:45:44: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int b = 1<<17; b/=2; ) if(ans[k] + b < size(a)) {
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
292 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
0 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
14 ms |
1260 KB |
Output is correct |
3 |
Correct |
152 ms |
9332 KB |
Output is correct |
4 |
Correct |
168 ms |
9352 KB |
Output is correct |
5 |
Correct |
193 ms |
9424 KB |
Output is correct |
6 |
Correct |
101 ms |
8624 KB |
Output is correct |
7 |
Correct |
118 ms |
8500 KB |
Output is correct |
8 |
Correct |
189 ms |
9440 KB |
Output is correct |
9 |
Correct |
167 ms |
8560 KB |
Output is correct |
10 |
Correct |
125 ms |
8816 KB |
Output is correct |
11 |
Correct |
111 ms |
7948 KB |
Output is correct |
12 |
Correct |
241 ms |
8348 KB |
Output is correct |
13 |
Correct |
197 ms |
8780 KB |
Output is correct |
14 |
Correct |
204 ms |
8772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1224 KB |
Output is correct |
2 |
Correct |
28 ms |
1956 KB |
Output is correct |
3 |
Correct |
40 ms |
1972 KB |
Output is correct |
4 |
Correct |
130 ms |
7200 KB |
Output is correct |
5 |
Correct |
82 ms |
7256 KB |
Output is correct |
6 |
Correct |
88 ms |
8260 KB |
Output is correct |
7 |
Correct |
71 ms |
5152 KB |
Output is correct |
8 |
Correct |
89 ms |
7520 KB |
Output is correct |
9 |
Correct |
88 ms |
6052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
18 ms |
1132 KB |
Output is correct |
3 |
Correct |
129 ms |
7456 KB |
Output is correct |
4 |
Correct |
197 ms |
9368 KB |
Output is correct |
5 |
Correct |
98 ms |
7744 KB |
Output is correct |
6 |
Correct |
131 ms |
8196 KB |
Output is correct |
7 |
Correct |
148 ms |
8608 KB |
Output is correct |
8 |
Correct |
131 ms |
8032 KB |
Output is correct |
9 |
Correct |
173 ms |
9312 KB |
Output is correct |
10 |
Correct |
157 ms |
8724 KB |
Output is correct |
11 |
Correct |
228 ms |
8856 KB |
Output is correct |
12 |
Correct |
157 ms |
8196 KB |
Output is correct |
13 |
Correct |
153 ms |
8384 KB |
Output is correct |
14 |
Correct |
96 ms |
7944 KB |
Output is correct |
15 |
Correct |
84 ms |
7872 KB |
Output is correct |
16 |
Correct |
114 ms |
7076 KB |
Output is correct |
17 |
Correct |
186 ms |
8764 KB |
Output is correct |
18 |
Correct |
222 ms |
8768 KB |
Output is correct |
19 |
Correct |
88 ms |
7648 KB |
Output is correct |
20 |
Correct |
90 ms |
7804 KB |
Output is correct |
21 |
Correct |
136 ms |
7580 KB |
Output is correct |
22 |
Correct |
85 ms |
6244 KB |
Output is correct |
23 |
Correct |
133 ms |
9072 KB |
Output is correct |
24 |
Correct |
192 ms |
8892 KB |
Output is correct |
25 |
Correct |
130 ms |
9028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1264 KB |
Output is correct |
2 |
Correct |
15 ms |
1272 KB |
Output is correct |
3 |
Correct |
192 ms |
9704 KB |
Output is correct |
4 |
Correct |
256 ms |
9044 KB |
Output is correct |
5 |
Correct |
247 ms |
9700 KB |
Output is correct |
6 |
Correct |
235 ms |
10652 KB |
Output is correct |
7 |
Correct |
299 ms |
10376 KB |
Output is correct |
8 |
Correct |
261 ms |
10068 KB |
Output is correct |
9 |
Correct |
167 ms |
3876 KB |
Output is correct |
10 |
Correct |
183 ms |
5428 KB |
Output is correct |
11 |
Correct |
179 ms |
6616 KB |
Output is correct |
12 |
Correct |
184 ms |
9664 KB |
Output is correct |
13 |
Correct |
231 ms |
10080 KB |
Output is correct |
14 |
Correct |
272 ms |
10308 KB |
Output is correct |
15 |
Correct |
256 ms |
10920 KB |
Output is correct |
16 |
Correct |
164 ms |
7812 KB |
Output is correct |
17 |
Correct |
111 ms |
9116 KB |
Output is correct |
18 |
Correct |
137 ms |
7724 KB |
Output is correct |
19 |
Correct |
150 ms |
9272 KB |
Output is correct |
20 |
Correct |
141 ms |
8616 KB |
Output is correct |
21 |
Correct |
269 ms |
11232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
1272 KB |
Output is correct |
2 |
Correct |
22 ms |
1352 KB |
Output is correct |
3 |
Correct |
223 ms |
9224 KB |
Output is correct |
4 |
Correct |
198 ms |
9156 KB |
Output is correct |
5 |
Correct |
234 ms |
9280 KB |
Output is correct |
6 |
Correct |
198 ms |
10496 KB |
Output is correct |
7 |
Correct |
230 ms |
9752 KB |
Output is correct |
8 |
Correct |
247 ms |
9876 KB |
Output is correct |
9 |
Correct |
223 ms |
9476 KB |
Output is correct |
10 |
Correct |
246 ms |
10532 KB |
Output is correct |
11 |
Correct |
261 ms |
10252 KB |
Output is correct |
12 |
Correct |
257 ms |
10644 KB |
Output is correct |
13 |
Correct |
122 ms |
4204 KB |
Output is correct |
14 |
Correct |
124 ms |
3692 KB |
Output is correct |
15 |
Correct |
187 ms |
7868 KB |
Output is correct |
16 |
Correct |
122 ms |
5424 KB |
Output is correct |
17 |
Correct |
207 ms |
6564 KB |
Output is correct |
18 |
Correct |
124 ms |
5384 KB |
Output is correct |
19 |
Correct |
181 ms |
9292 KB |
Output is correct |
20 |
Correct |
214 ms |
10188 KB |
Output is correct |
21 |
Correct |
289 ms |
10804 KB |
Output is correct |
22 |
Correct |
225 ms |
10736 KB |
Output is correct |
23 |
Correct |
323 ms |
10352 KB |
Output is correct |
24 |
Correct |
202 ms |
10308 KB |
Output is correct |
25 |
Correct |
279 ms |
9984 KB |
Output is correct |
26 |
Correct |
234 ms |
10492 KB |
Output is correct |
27 |
Correct |
117 ms |
8248 KB |
Output is correct |
28 |
Correct |
147 ms |
9208 KB |
Output is correct |
29 |
Correct |
138 ms |
9836 KB |
Output is correct |
30 |
Correct |
159 ms |
9572 KB |
Output is correct |
31 |
Correct |
148 ms |
9572 KB |
Output is correct |
32 |
Correct |
155 ms |
9440 KB |
Output is correct |
33 |
Correct |
127 ms |
9800 KB |
Output is correct |
34 |
Correct |
126 ms |
8508 KB |
Output is correct |
35 |
Correct |
141 ms |
8692 KB |
Output is correct |
36 |
Correct |
179 ms |
9392 KB |
Output is correct |
37 |
Correct |
112 ms |
9172 KB |
Output is correct |
38 |
Correct |
188 ms |
9464 KB |
Output is correct |
39 |
Correct |
253 ms |
11008 KB |
Output is correct |
40 |
Correct |
285 ms |
11000 KB |
Output is correct |
41 |
Correct |
185 ms |
11016 KB |
Output is correct |
42 |
Correct |
356 ms |
10496 KB |
Output is correct |