#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
const int MN = 150005;
ll m, st, lo, hi, mm, i, x, y, vis[MN], s, t, d[MN], u[MN]; vector<int> q;
map<pair<ll,ll>,ll> id;
vector<ll> adj[MN], tr[MN], ls;
queue<ll> qq;
void sett(ll l){
for(int i=0;i<q.size();i++)
q[i]=(i<=l);
}
void dfs(ll n){
for(auto v : tr[n]){
ls.push_back(id[{v, n}]);
d[v] = d[n]+1; dfs(v);
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
A = B = 0; m = U.size();
for(i=0;i<m;i++) q.push_back(0);
for(i=0;i<m;i++){
x = U[i], y = V[i];
id[{x,y}]=id[{y,x}]=i;
adj[x].push_back(y);
adj[y].push_back(x);
}
st = ask(q);
lo = 0, hi = m;
while(lo<hi){
ll m = lo+hi>>1;
sett(m);
bool heh = (ask(q)==st);
if(heh) lo=m+1;
else hi=m;
}
mm = lo-1; sett(mm);
x = U[mm+1], y = V[mm+1];
qq.push(x); qq.push(y); vis[x]=vis[y]=1;
while(qq.size()){
x = qq.front(); qq.pop();
for(auto v : adj[x]){
if(id[{x,v}]>mm&&!vis[v]){
vis[v] = 1;
qq.push(v);
tr[x].push_back(v);
u[id[{x,v}]]=1;
}
}
}
for (int i = 0; i <= N; i++) random_shuffle(tr[i].begin(), tr[i].end());
u[mm+1]=1;
x = U[mm+1], y = V[mm+1];
dfs(x);
lo = 0; hi = ls.size();
while(lo<hi){
ll mmm = lo+hi>>1;
for(i=0;i<m;i++) q[i]=!u[i];
for(i=mmm;i<ls.size();i++) q[ls[i]]=1;
bool heh = (ask(q)==st);
if(heh) hi=mmm;
else lo=mmm+1;
}
if(lo==0){
s = U[mm+1];
}
else{
x = U[ls[lo-1]], y = V[ls[lo-1]];
if(d[x]>d[y]) s = x;
else s = y;
}
ls.clear();
x = U[mm+1], y = V[mm+1];
dfs(y);
lo = 0; hi = ls.size();
while(lo<hi){
ll mmm = lo+hi>>1;
for(i=0;i<m;i++) q[i]=!u[i];
for(i=mmm;i<ls.size();i++) q[ls[i]]=1;
bool heh = (ask(q)==st);
if(heh) hi=mmm;
else lo=mmm+1;
}
if(lo==0){
t = V[mm+1];
}
else{
x = U[ls[lo-1]], y = V[ls[lo-1]];
if(d[x]>d[y]) t = x;
else t = y;
}
answer(s, t);
}
Compilation message
highway.cpp: In function 'void sett(ll)':
highway.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<q.size();i++)
~^~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:33:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m = lo+hi>>1;
~~^~~
highway.cpp:59:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mmm = lo+hi>>1;
~~^~~
highway.cpp:61:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=mmm;i<ls.size();i++) q[ls[i]]=1;
~^~~~~~~~~~
highway.cpp:79:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mmm = lo+hi>>1;
~~^~~
highway.cpp:81:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=mmm;i<ls.size();i++) q[ls[i]]=1;
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7400 KB |
Output is correct |
2 |
Correct |
8 ms |
7392 KB |
Output is correct |
3 |
Correct |
8 ms |
7336 KB |
Output is correct |
4 |
Correct |
9 ms |
7404 KB |
Output is correct |
5 |
Correct |
8 ms |
7288 KB |
Output is correct |
6 |
Correct |
9 ms |
7400 KB |
Output is correct |
7 |
Correct |
8 ms |
7288 KB |
Output is correct |
8 |
Correct |
8 ms |
7288 KB |
Output is correct |
9 |
Correct |
8 ms |
7476 KB |
Output is correct |
10 |
Correct |
8 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7396 KB |
Output is correct |
12 |
Correct |
8 ms |
7288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7560 KB |
Output is correct |
2 |
Correct |
49 ms |
9852 KB |
Output is correct |
3 |
Correct |
527 ms |
28296 KB |
Output is correct |
4 |
Correct |
477 ms |
28232 KB |
Output is correct |
5 |
Correct |
560 ms |
28764 KB |
Output is correct |
6 |
Correct |
461 ms |
27536 KB |
Output is correct |
7 |
Correct |
467 ms |
27388 KB |
Output is correct |
8 |
Correct |
576 ms |
28748 KB |
Output is correct |
9 |
Correct |
457 ms |
27392 KB |
Output is correct |
10 |
Correct |
517 ms |
27856 KB |
Output is correct |
11 |
Correct |
354 ms |
26584 KB |
Output is correct |
12 |
Correct |
550 ms |
30940 KB |
Output is correct |
13 |
Correct |
568 ms |
31356 KB |
Output is correct |
14 |
Correct |
639 ms |
31476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
10616 KB |
Output is correct |
2 |
Correct |
65 ms |
13620 KB |
Output is correct |
3 |
Correct |
97 ms |
13300 KB |
Output is correct |
4 |
Correct |
255 ms |
32100 KB |
Output is correct |
5 |
Correct |
280 ms |
32244 KB |
Output is correct |
6 |
Correct |
280 ms |
34684 KB |
Output is correct |
7 |
Correct |
229 ms |
24072 KB |
Output is correct |
8 |
Correct |
288 ms |
33336 KB |
Output is correct |
9 |
Correct |
273 ms |
27156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7592 KB |
Output is correct |
2 |
Correct |
46 ms |
9592 KB |
Output is correct |
3 |
Correct |
433 ms |
24312 KB |
Output is correct |
4 |
Correct |
524 ms |
28264 KB |
Output is correct |
5 |
Correct |
327 ms |
25796 KB |
Output is correct |
6 |
Correct |
379 ms |
25704 KB |
Output is correct |
7 |
Correct |
481 ms |
27256 KB |
Output is correct |
8 |
Correct |
376 ms |
26084 KB |
Output is correct |
9 |
Correct |
555 ms |
28400 KB |
Output is correct |
10 |
Correct |
455 ms |
27564 KB |
Output is correct |
11 |
Correct |
572 ms |
30880 KB |
Output is correct |
12 |
Correct |
544 ms |
31232 KB |
Output is correct |
13 |
Correct |
515 ms |
30056 KB |
Output is correct |
14 |
Correct |
422 ms |
26916 KB |
Output is correct |
15 |
Correct |
381 ms |
25916 KB |
Output is correct |
16 |
Correct |
344 ms |
23968 KB |
Output is correct |
17 |
Correct |
567 ms |
30688 KB |
Output is correct |
18 |
Correct |
562 ms |
31568 KB |
Output is correct |
19 |
Correct |
350 ms |
24468 KB |
Output is correct |
20 |
Correct |
355 ms |
25604 KB |
Output is correct |
21 |
Correct |
438 ms |
27444 KB |
Output is correct |
22 |
Correct |
405 ms |
26332 KB |
Output is correct |
23 |
Correct |
521 ms |
27860 KB |
Output is correct |
24 |
Correct |
548 ms |
28524 KB |
Output is correct |
25 |
Correct |
572 ms |
36216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
9868 KB |
Output is correct |
2 |
Correct |
63 ms |
10076 KB |
Output is correct |
3 |
Correct |
639 ms |
30420 KB |
Output is correct |
4 |
Correct |
661 ms |
31320 KB |
Output is correct |
5 |
Correct |
782 ms |
34720 KB |
Output is correct |
6 |
Correct |
896 ms |
35080 KB |
Output is correct |
7 |
Correct |
800 ms |
34892 KB |
Output is correct |
8 |
Correct |
777 ms |
35120 KB |
Output is correct |
9 |
Correct |
535 ms |
30008 KB |
Output is correct |
10 |
Correct |
602 ms |
32160 KB |
Output is correct |
11 |
Correct |
672 ms |
32244 KB |
Output is correct |
12 |
Correct |
802 ms |
34120 KB |
Output is correct |
13 |
Correct |
864 ms |
34616 KB |
Output is correct |
14 |
Correct |
840 ms |
35112 KB |
Output is correct |
15 |
Correct |
1020 ms |
35492 KB |
Output is correct |
16 |
Correct |
676 ms |
32692 KB |
Output is correct |
17 |
Correct |
466 ms |
27792 KB |
Output is correct |
18 |
Correct |
382 ms |
26588 KB |
Output is correct |
19 |
Correct |
498 ms |
28792 KB |
Output is correct |
20 |
Correct |
422 ms |
27420 KB |
Output is correct |
21 |
Correct |
813 ms |
36112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
9936 KB |
Output is correct |
2 |
Correct |
52 ms |
10280 KB |
Output is correct |
3 |
Correct |
624 ms |
30192 KB |
Output is correct |
4 |
Correct |
655 ms |
30848 KB |
Output is correct |
5 |
Correct |
742 ms |
31568 KB |
Output is correct |
6 |
Correct |
785 ms |
35264 KB |
Output is correct |
7 |
Correct |
655 ms |
30564 KB |
Output is correct |
8 |
Correct |
680 ms |
31296 KB |
Output is correct |
9 |
Correct |
669 ms |
31444 KB |
Output is correct |
10 |
Correct |
791 ms |
34976 KB |
Output is correct |
11 |
Correct |
833 ms |
35160 KB |
Output is correct |
12 |
Correct |
797 ms |
34908 KB |
Output is correct |
13 |
Correct |
559 ms |
30972 KB |
Output is correct |
14 |
Correct |
545 ms |
31088 KB |
Output is correct |
15 |
Correct |
686 ms |
33228 KB |
Output is correct |
16 |
Correct |
590 ms |
32176 KB |
Output is correct |
17 |
Correct |
685 ms |
32452 KB |
Output is correct |
18 |
Correct |
644 ms |
32016 KB |
Output is correct |
19 |
Correct |
773 ms |
33976 KB |
Output is correct |
20 |
Correct |
771 ms |
34948 KB |
Output is correct |
21 |
Correct |
830 ms |
35132 KB |
Output is correct |
22 |
Correct |
799 ms |
34992 KB |
Output is correct |
23 |
Correct |
836 ms |
35128 KB |
Output is correct |
24 |
Correct |
784 ms |
35120 KB |
Output is correct |
25 |
Correct |
756 ms |
35348 KB |
Output is correct |
26 |
Correct |
827 ms |
35528 KB |
Output is correct |
27 |
Correct |
429 ms |
27488 KB |
Output is correct |
28 |
Correct |
456 ms |
28536 KB |
Output is correct |
29 |
Correct |
490 ms |
29288 KB |
Output is correct |
30 |
Correct |
502 ms |
29176 KB |
Output is correct |
31 |
Correct |
494 ms |
28656 KB |
Output is correct |
32 |
Correct |
484 ms |
28568 KB |
Output is correct |
33 |
Correct |
534 ms |
29388 KB |
Output is correct |
34 |
Correct |
497 ms |
27812 KB |
Output is correct |
35 |
Correct |
501 ms |
28036 KB |
Output is correct |
36 |
Correct |
542 ms |
28704 KB |
Output is correct |
37 |
Correct |
466 ms |
28532 KB |
Output is correct |
38 |
Correct |
571 ms |
29464 KB |
Output is correct |
39 |
Correct |
814 ms |
36552 KB |
Output is correct |
40 |
Correct |
848 ms |
36964 KB |
Output is correct |
41 |
Correct |
862 ms |
36028 KB |
Output is correct |
42 |
Correct |
832 ms |
35488 KB |
Output is correct |