#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) {
vector<vector<pair<int, int>>> adj(n);
int m = u.size();
vector<int> w(m);
for (int i = 0; i < m; ++i) {
adj[u[i]].emplace_back(v[i], i);
adj[v[i]].emplace_back(u[i], i);
}
long long value = ask(w);
int l = 0, r = m - 2, e = m - 1;
while (l <= r) {
int mid = l + r >> 1;
for (int i = 0; i < m; ++i) {
w[i] = i <= mid;
}
if (ask(w) != value) {
e = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
vector<int> tree, left, right, visit(n);
queue<int> q;
q.push(u[e]);
visit[u[e]] = 1;
left.push_back(u[e]);
q.push(v[e]);
visit[v[e]] = 2;
right.push_back(v[e]);
tree.push_back(e);
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto p : adj[x]) {
int y = p.first, w = p.second;
if (!visit[y]) {
tree.push_back(w);
q.push(y);
if (visit[x] == 1) {
visit[y] = 1;
left.push_back(y);
} else {
visit[y] = 2;
right.push_back(y);
}
}
}
}
auto solve = [&](vector<int> nodes) {
int l = 0, r = nodes.size() - 2, p = nodes.size() - 1;
while (l <= r) {
int mid = l + r >> 1;
vector<bool> ban(n, false);
for (int i = mid + 1; i < nodes.size(); ++i) {
ban[nodes[i]] = true;
}
for (int i = 0; i < m; ++i) {
w[i] = 1;
}
for (auto e : tree) {
if (!ban[u[e]] && !ban[v[e]]) {
w[e] = 0;
}
}
if (ask(w) == value) {
p = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return nodes[p];
};
answer(solve(left), solve(right));
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:17:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
highway.cpp: In lambda function:
highway.cpp:59:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
highway.cpp:61:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = mid + 1; i < nodes.size(); ++i) {
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
328 KB |
Output is correct |
10 |
Correct |
2 ms |
320 KB |
Output is correct |
11 |
Correct |
2 ms |
248 KB |
Output is correct |
12 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
392 KB |
Output is correct |
2 |
Correct |
19 ms |
1320 KB |
Output is correct |
3 |
Correct |
205 ms |
9184 KB |
Output is correct |
4 |
Correct |
210 ms |
9236 KB |
Output is correct |
5 |
Correct |
230 ms |
9308 KB |
Output is correct |
6 |
Correct |
185 ms |
9256 KB |
Output is correct |
7 |
Correct |
254 ms |
9236 KB |
Output is correct |
8 |
Correct |
202 ms |
9160 KB |
Output is correct |
9 |
Correct |
227 ms |
9308 KB |
Output is correct |
10 |
Correct |
218 ms |
9232 KB |
Output is correct |
11 |
Correct |
228 ms |
8604 KB |
Output is correct |
12 |
Correct |
236 ms |
8580 KB |
Output is correct |
13 |
Correct |
227 ms |
8752 KB |
Output is correct |
14 |
Correct |
218 ms |
8656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1216 KB |
Output is correct |
2 |
Correct |
42 ms |
2216 KB |
Output is correct |
3 |
Correct |
56 ms |
3108 KB |
Output is correct |
4 |
Correct |
191 ms |
8488 KB |
Output is correct |
5 |
Correct |
182 ms |
8484 KB |
Output is correct |
6 |
Correct |
160 ms |
8628 KB |
Output is correct |
7 |
Correct |
176 ms |
8672 KB |
Output is correct |
8 |
Correct |
152 ms |
8448 KB |
Output is correct |
9 |
Correct |
176 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
396 KB |
Output is correct |
2 |
Correct |
46 ms |
1340 KB |
Output is correct |
3 |
Correct |
135 ms |
7264 KB |
Output is correct |
4 |
Correct |
203 ms |
9324 KB |
Output is correct |
5 |
Correct |
193 ms |
9152 KB |
Output is correct |
6 |
Correct |
178 ms |
9144 KB |
Output is correct |
7 |
Correct |
179 ms |
9244 KB |
Output is correct |
8 |
Correct |
199 ms |
9132 KB |
Output is correct |
9 |
Correct |
234 ms |
9168 KB |
Output is correct |
10 |
Correct |
218 ms |
9184 KB |
Output is correct |
11 |
Correct |
214 ms |
8600 KB |
Output is correct |
12 |
Correct |
223 ms |
8680 KB |
Output is correct |
13 |
Correct |
194 ms |
8632 KB |
Output is correct |
14 |
Correct |
228 ms |
8576 KB |
Output is correct |
15 |
Correct |
206 ms |
9160 KB |
Output is correct |
16 |
Correct |
197 ms |
9160 KB |
Output is correct |
17 |
Correct |
224 ms |
8624 KB |
Output is correct |
18 |
Correct |
239 ms |
8684 KB |
Output is correct |
19 |
Correct |
208 ms |
9156 KB |
Output is correct |
20 |
Correct |
222 ms |
8600 KB |
Output is correct |
21 |
Correct |
169 ms |
9928 KB |
Output is correct |
22 |
Correct |
179 ms |
9832 KB |
Output is correct |
23 |
Correct |
226 ms |
9560 KB |
Output is correct |
24 |
Correct |
195 ms |
9500 KB |
Output is correct |
25 |
Correct |
221 ms |
8700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1392 KB |
Output is correct |
2 |
Correct |
29 ms |
1328 KB |
Output is correct |
3 |
Correct |
242 ms |
9556 KB |
Output is correct |
4 |
Correct |
278 ms |
9900 KB |
Output is correct |
5 |
Correct |
301 ms |
10864 KB |
Output is correct |
6 |
Correct |
340 ms |
10804 KB |
Output is correct |
7 |
Correct |
285 ms |
10872 KB |
Output is correct |
8 |
Correct |
319 ms |
10988 KB |
Output is correct |
9 |
Correct |
244 ms |
7280 KB |
Output is correct |
10 |
Correct |
258 ms |
7456 KB |
Output is correct |
11 |
Correct |
239 ms |
8404 KB |
Output is correct |
12 |
Correct |
321 ms |
9936 KB |
Output is correct |
13 |
Correct |
275 ms |
10436 KB |
Output is correct |
14 |
Correct |
339 ms |
10888 KB |
Output is correct |
15 |
Correct |
323 ms |
10824 KB |
Output is correct |
16 |
Correct |
300 ms |
8352 KB |
Output is correct |
17 |
Correct |
207 ms |
9552 KB |
Output is correct |
18 |
Correct |
217 ms |
9752 KB |
Output is correct |
19 |
Correct |
213 ms |
9632 KB |
Output is correct |
20 |
Correct |
203 ms |
9688 KB |
Output is correct |
21 |
Correct |
317 ms |
10920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1352 KB |
Output is correct |
2 |
Correct |
52 ms |
1340 KB |
Output is correct |
3 |
Correct |
260 ms |
9480 KB |
Output is correct |
4 |
Correct |
267 ms |
9704 KB |
Output is correct |
5 |
Correct |
257 ms |
9932 KB |
Output is correct |
6 |
Correct |
262 ms |
10880 KB |
Output is correct |
7 |
Correct |
231 ms |
9668 KB |
Output is correct |
8 |
Correct |
259 ms |
9672 KB |
Output is correct |
9 |
Correct |
285 ms |
9952 KB |
Output is correct |
10 |
Correct |
323 ms |
10792 KB |
Output is correct |
11 |
Correct |
333 ms |
10908 KB |
Output is correct |
12 |
Correct |
315 ms |
10792 KB |
Output is correct |
13 |
Correct |
268 ms |
8332 KB |
Output is correct |
14 |
Correct |
260 ms |
7456 KB |
Output is correct |
15 |
Correct |
233 ms |
8328 KB |
Output is correct |
16 |
Correct |
248 ms |
7524 KB |
Output is correct |
17 |
Correct |
270 ms |
8396 KB |
Output is correct |
18 |
Correct |
258 ms |
7516 KB |
Output is correct |
19 |
Correct |
282 ms |
9908 KB |
Output is correct |
20 |
Correct |
294 ms |
10396 KB |
Output is correct |
21 |
Correct |
329 ms |
10924 KB |
Output is correct |
22 |
Correct |
324 ms |
10836 KB |
Output is correct |
23 |
Correct |
333 ms |
10856 KB |
Output is correct |
24 |
Correct |
327 ms |
10920 KB |
Output is correct |
25 |
Correct |
310 ms |
10884 KB |
Output is correct |
26 |
Correct |
336 ms |
10916 KB |
Output is correct |
27 |
Correct |
213 ms |
9700 KB |
Output is correct |
28 |
Correct |
214 ms |
9704 KB |
Output is correct |
29 |
Correct |
211 ms |
10048 KB |
Output is correct |
30 |
Correct |
217 ms |
9720 KB |
Output is correct |
31 |
Correct |
217 ms |
9712 KB |
Output is correct |
32 |
Correct |
204 ms |
9588 KB |
Output is correct |
33 |
Correct |
213 ms |
9880 KB |
Output is correct |
34 |
Correct |
218 ms |
9652 KB |
Output is correct |
35 |
Correct |
204 ms |
9752 KB |
Output is correct |
36 |
Correct |
221 ms |
9564 KB |
Output is correct |
37 |
Correct |
222 ms |
9972 KB |
Output is correct |
38 |
Correct |
209 ms |
9716 KB |
Output is correct |
39 |
Correct |
315 ms |
10900 KB |
Output is correct |
40 |
Correct |
347 ms |
11068 KB |
Output is correct |
41 |
Correct |
339 ms |
10952 KB |
Output is correct |
42 |
Correct |
336 ms |
10816 KB |
Output is correct |