#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
int n, m;
vector<pair<int, int>> adj[100005];
vector<int> w;
long long dist;
vector<int> vertices[2];
int find(vector<int> arr){
int lo = 0, hi = arr.size()-1;
while(lo < hi){
int mid = lo+(hi-lo+1)/2;
for(int i = 0; i<m; i++) w[i] = 0;
for(int i = mid; i<arr.size(); i++) for(auto u : adj[arr[i]]) w[u.second] = 1;
if(ask(w) != dist) lo = mid;
else hi = mid-1;
}
return arr[lo];
}
void find_pair(int nn, vector<int> uu, vector<int> vv, int aa, int bb){
n = nn, m = uu.size();
for(int i = 0; i<m; i++){
int a = uu[i], b = vv[i];
adj[a].push_back({b, i});
adj[b].push_back({a, i});
}
w.assign(m, 0);
dist = ask(w);
int lo = 0, hi = m-1;
while(lo < hi){
int mid = lo+(hi-lo)/2;
for(int i = 0; i<m; i++) w[i] = i<=mid;
if(ask(w) != dist) hi = mid;
else lo = mid+1;
}
vector<int> d(n, n);
queue<pair<int, int>> q;
q.push({uu[lo], 0});
q.push({vv[lo], 1});
d[uu[lo]] = d[vv[lo]] = 0;
while(!q.empty()){
int v = q.front().first; int t = q.front().second;
vertices[t].push_back(v);
q.pop();
for(auto u : adj[v]){
if(d[u.first]>d[v]+1){
d[u.first] = d[v]+1;
q.push({u.first, t});
}
}
}
// for(auto x : vertices[0]) cout << x << " ";
// cout << endl;
// for(auto x : vertices[1]) cout << x << " ";
// cout << endl;
answer(find(vertices[0]), find(vertices[1]));
}
Compilation message
highway.cpp: In function 'int find(std::vector<int>)':
highway.cpp:16:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = mid; i<arr.size(); i++) for(auto u : adj[arr[i]]) w[u.second] = 1;
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2808 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2732 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2668 KB |
Output is correct |
9 |
Correct |
3 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2668 KB |
Output is correct |
12 |
Correct |
3 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2796 KB |
Output is correct |
2 |
Correct |
23 ms |
3436 KB |
Output is correct |
3 |
Correct |
271 ms |
9280 KB |
Output is correct |
4 |
Correct |
223 ms |
9232 KB |
Output is correct |
5 |
Correct |
235 ms |
9200 KB |
Output is correct |
6 |
Correct |
216 ms |
9228 KB |
Output is correct |
7 |
Correct |
240 ms |
9248 KB |
Output is correct |
8 |
Correct |
397 ms |
9368 KB |
Output is correct |
9 |
Correct |
347 ms |
9280 KB |
Output is correct |
10 |
Correct |
264 ms |
9248 KB |
Output is correct |
11 |
Correct |
330 ms |
8636 KB |
Output is correct |
12 |
Correct |
298 ms |
8540 KB |
Output is correct |
13 |
Correct |
285 ms |
8572 KB |
Output is correct |
14 |
Correct |
279 ms |
8624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3308 KB |
Output is correct |
2 |
Correct |
29 ms |
4040 KB |
Output is correct |
3 |
Correct |
46 ms |
4660 KB |
Output is correct |
4 |
Correct |
152 ms |
8376 KB |
Output is correct |
5 |
Correct |
130 ms |
8396 KB |
Output is correct |
6 |
Correct |
119 ms |
8504 KB |
Output is correct |
7 |
Correct |
138 ms |
8512 KB |
Output is correct |
8 |
Correct |
127 ms |
8528 KB |
Output is correct |
9 |
Correct |
136 ms |
8544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2796 KB |
Output is correct |
2 |
Correct |
23 ms |
3436 KB |
Output is correct |
3 |
Correct |
245 ms |
7708 KB |
Output is correct |
4 |
Correct |
299 ms |
9132 KB |
Output is correct |
5 |
Correct |
342 ms |
9188 KB |
Output is correct |
6 |
Correct |
358 ms |
9144 KB |
Output is correct |
7 |
Correct |
331 ms |
9256 KB |
Output is correct |
8 |
Correct |
359 ms |
9292 KB |
Output is correct |
9 |
Correct |
294 ms |
9208 KB |
Output is correct |
10 |
Correct |
315 ms |
9296 KB |
Output is correct |
11 |
Correct |
206 ms |
8496 KB |
Output is correct |
12 |
Correct |
261 ms |
8564 KB |
Output is correct |
13 |
Correct |
320 ms |
8452 KB |
Output is correct |
14 |
Correct |
297 ms |
8400 KB |
Output is correct |
15 |
Correct |
373 ms |
9188 KB |
Output is correct |
16 |
Correct |
373 ms |
9212 KB |
Output is correct |
17 |
Correct |
260 ms |
8564 KB |
Output is correct |
18 |
Correct |
312 ms |
8628 KB |
Output is correct |
19 |
Correct |
361 ms |
9156 KB |
Output is correct |
20 |
Correct |
366 ms |
8672 KB |
Output is correct |
21 |
Correct |
168 ms |
10004 KB |
Output is correct |
22 |
Correct |
160 ms |
9952 KB |
Output is correct |
23 |
Correct |
150 ms |
9368 KB |
Output is correct |
24 |
Correct |
178 ms |
9372 KB |
Output is correct |
25 |
Correct |
193 ms |
8684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
3476 KB |
Output is correct |
2 |
Correct |
25 ms |
3564 KB |
Output is correct |
3 |
Correct |
243 ms |
9532 KB |
Output is correct |
4 |
Correct |
303 ms |
9964 KB |
Output is correct |
5 |
Correct |
446 ms |
11112 KB |
Output is correct |
6 |
Correct |
495 ms |
11028 KB |
Output is correct |
7 |
Correct |
484 ms |
11180 KB |
Output is correct |
8 |
Correct |
323 ms |
11036 KB |
Output is correct |
9 |
Correct |
234 ms |
8784 KB |
Output is correct |
10 |
Correct |
259 ms |
9220 KB |
Output is correct |
11 |
Correct |
162 ms |
9632 KB |
Output is correct |
12 |
Correct |
414 ms |
10460 KB |
Output is correct |
13 |
Correct |
433 ms |
10912 KB |
Output is correct |
14 |
Correct |
423 ms |
11004 KB |
Output is correct |
15 |
Correct |
385 ms |
10920 KB |
Output is correct |
16 |
Correct |
288 ms |
9748 KB |
Output is correct |
17 |
Correct |
182 ms |
9692 KB |
Output is correct |
18 |
Correct |
220 ms |
9944 KB |
Output is correct |
19 |
Correct |
147 ms |
9820 KB |
Output is correct |
20 |
Correct |
269 ms |
9936 KB |
Output is correct |
21 |
Correct |
457 ms |
10936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3436 KB |
Output is correct |
2 |
Correct |
19 ms |
3436 KB |
Output is correct |
3 |
Correct |
372 ms |
9760 KB |
Output is correct |
4 |
Correct |
385 ms |
9904 KB |
Output is correct |
5 |
Correct |
362 ms |
10008 KB |
Output is correct |
6 |
Correct |
384 ms |
10936 KB |
Output is correct |
7 |
Correct |
319 ms |
9776 KB |
Output is correct |
8 |
Correct |
324 ms |
9856 KB |
Output is correct |
9 |
Correct |
381 ms |
10148 KB |
Output is correct |
10 |
Correct |
489 ms |
11152 KB |
Output is correct |
11 |
Correct |
411 ms |
10968 KB |
Output is correct |
12 |
Correct |
435 ms |
11016 KB |
Output is correct |
13 |
Correct |
248 ms |
9820 KB |
Output is correct |
14 |
Correct |
206 ms |
9228 KB |
Output is correct |
15 |
Correct |
279 ms |
9616 KB |
Output is correct |
16 |
Correct |
263 ms |
9216 KB |
Output is correct |
17 |
Correct |
263 ms |
9632 KB |
Output is correct |
18 |
Correct |
198 ms |
9284 KB |
Output is correct |
19 |
Correct |
379 ms |
10780 KB |
Output is correct |
20 |
Correct |
396 ms |
10804 KB |
Output is correct |
21 |
Correct |
501 ms |
11112 KB |
Output is correct |
22 |
Correct |
502 ms |
11000 KB |
Output is correct |
23 |
Correct |
411 ms |
11136 KB |
Output is correct |
24 |
Correct |
460 ms |
11020 KB |
Output is correct |
25 |
Correct |
426 ms |
10908 KB |
Output is correct |
26 |
Correct |
423 ms |
11080 KB |
Output is correct |
27 |
Correct |
242 ms |
9900 KB |
Output is correct |
28 |
Correct |
328 ms |
9828 KB |
Output is correct |
29 |
Correct |
298 ms |
9956 KB |
Output is correct |
30 |
Correct |
217 ms |
9820 KB |
Output is correct |
31 |
Correct |
261 ms |
9840 KB |
Output is correct |
32 |
Correct |
256 ms |
9728 KB |
Output is correct |
33 |
Correct |
214 ms |
9948 KB |
Output is correct |
34 |
Correct |
290 ms |
10220 KB |
Output is correct |
35 |
Correct |
247 ms |
9816 KB |
Output is correct |
36 |
Correct |
271 ms |
9760 KB |
Output is correct |
37 |
Correct |
268 ms |
10112 KB |
Output is correct |
38 |
Correct |
159 ms |
9944 KB |
Output is correct |
39 |
Correct |
393 ms |
10900 KB |
Output is correct |
40 |
Correct |
461 ms |
10972 KB |
Output is correct |
41 |
Correct |
237 ms |
11036 KB |
Output is correct |
42 |
Correct |
468 ms |
10912 KB |
Output is correct |