#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define X first
#define Y second
#define pb push_back
const int MAX=2e5+3;
using ii = pair < int , int >;
vector < int > pr[MAX];
int d[MAX],D[MAX];
int C[MAX];
queue < int > Q;
void bfs(int v){
memset(d,-1,sizeof d);
Q.push(v);d[v]=0;
while(!Q.empty()){
int p = Q.front();Q.pop();
for(int u:pr[p]) if(d[u]==-1){
d[u]=d[p]+1;Q.push(u);
}
}
}
void BFS(int v){
memset(D,-1,sizeof D);
Q.push(v);D[v]=0;
while(!Q.empty()){
int p = Q.front();Q.pop();
for(int u:pr[p]) if(D[u]==-1){
D[u]=D[p]+1;Q.push(u);
}
}
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
vector < int > w(M);
for (int i = 0; i < M; ++i)
w[i] = 0;
long long res = ask(w);
int b=1,e=M-1,sp=0;
while(b<=e){
int mi=b+e>>1;
for(int i=0;i<M;i++)w[i]=(i<mi);
ll temp=ask(w);
if(temp==res){
b=mi+1;sp=mi;
}
else
e=mi-1;
}
for(int i=sp;i<M;i++){
pr[U[i]].pb(V[i]);
pr[V[i]].pb(U[i]);
}
int u=U[sp],v=V[sp];
BFS(u);bfs(v);
vector < ii > vec;
for(int i=0;i<n;i++){
if(d[i]-D[i]==1){
vec.pb(ii(D[i],i));
}
}
sort(vec.begin(),vec.end());
int sz=vec.size();
for(int i=0;i<sz;i++) C[vec[i].Y]=i;
for(int i=0;i<sp;i++)w[i]=1;
b=1,e=sz-1;int an=sz;
while(b<=e){
int mi=b+e>>1;
for(int i=sp;i<M;i++)
w[i]=(max(C[U[i]],C[V[i]])>=mi);
ll temp=ask(w);
if(temp==res){
an=mi;e=mi-1;
}
else b=mi+1;
}
int ans1=vec[an-1].Y;
vec.clear();
for(int i=0;i<n;i++){
if(D[i]-d[i]==1){
vec.pb(ii(D[i],i));
}
}
sort(vec.begin(),vec.end());
sz=vec.size();
memset(C,0,sizeof C);
for(int i=0;i<sz;i++) C[vec[i].Y]=i;
for(int i=0;i<sp;i++)w[i]=1;
b=1,e=sz-1;an=sz;
while(b<=e){
int mi=b+e>>1;
for(int i=sp;i<M;i++)
w[i]=(max(C[U[i]],C[V[i]])>=mi);
ll temp=ask(w);
if(temp==res){
an=mi;e=mi-1;
}
else b=mi+1;
}
int ans2=vec[an-1].Y;
answer(ans1,ans2);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mi=b+e>>1;
| ~^~
highway.cpp:73:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int mi=b+e>>1;
| ~^~
highway.cpp:100:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
100 | int mi=b+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7240 KB |
Output is correct |
2 |
Correct |
7 ms |
7240 KB |
Output is correct |
3 |
Correct |
6 ms |
7292 KB |
Output is correct |
4 |
Correct |
8 ms |
7248 KB |
Output is correct |
5 |
Correct |
5 ms |
7240 KB |
Output is correct |
6 |
Correct |
6 ms |
7240 KB |
Output is correct |
7 |
Correct |
6 ms |
7240 KB |
Output is correct |
8 |
Correct |
7 ms |
7300 KB |
Output is correct |
9 |
Correct |
6 ms |
7296 KB |
Output is correct |
10 |
Correct |
7 ms |
7292 KB |
Output is correct |
11 |
Correct |
6 ms |
7240 KB |
Output is correct |
12 |
Correct |
6 ms |
7300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7316 KB |
Output is correct |
2 |
Correct |
18 ms |
8000 KB |
Output is correct |
3 |
Correct |
172 ms |
12548 KB |
Output is correct |
4 |
Correct |
244 ms |
12676 KB |
Output is correct |
5 |
Correct |
155 ms |
12880 KB |
Output is correct |
6 |
Correct |
215 ms |
12508 KB |
Output is correct |
7 |
Correct |
139 ms |
12460 KB |
Output is correct |
8 |
Correct |
258 ms |
12880 KB |
Output is correct |
9 |
Correct |
142 ms |
12272 KB |
Output is correct |
10 |
Correct |
195 ms |
12700 KB |
Output is correct |
11 |
Correct |
171 ms |
12116 KB |
Output is correct |
12 |
Correct |
172 ms |
12544 KB |
Output is correct |
13 |
Correct |
213 ms |
12816 KB |
Output is correct |
14 |
Correct |
168 ms |
12752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
7864 KB |
Output is correct |
2 |
Correct |
53 ms |
8484 KB |
Output is correct |
3 |
Correct |
66 ms |
8072 KB |
Output is correct |
4 |
Correct |
132 ms |
11476 KB |
Output is correct |
5 |
Correct |
111 ms |
11564 KB |
Output is correct |
6 |
Correct |
108 ms |
12040 KB |
Output is correct |
7 |
Correct |
178 ms |
9360 KB |
Output is correct |
8 |
Correct |
106 ms |
11712 KB |
Output is correct |
9 |
Correct |
177 ms |
10148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7368 KB |
Output is correct |
2 |
Correct |
26 ms |
7856 KB |
Output is correct |
3 |
Correct |
170 ms |
11696 KB |
Output is correct |
4 |
Correct |
226 ms |
12652 KB |
Output is correct |
5 |
Correct |
201 ms |
11596 KB |
Output is correct |
6 |
Correct |
195 ms |
11812 KB |
Output is correct |
7 |
Correct |
211 ms |
12260 KB |
Output is correct |
8 |
Correct |
207 ms |
11860 KB |
Output is correct |
9 |
Correct |
257 ms |
12632 KB |
Output is correct |
10 |
Correct |
162 ms |
12552 KB |
Output is correct |
11 |
Correct |
164 ms |
12676 KB |
Output is correct |
12 |
Correct |
258 ms |
12648 KB |
Output is correct |
13 |
Correct |
266 ms |
12580 KB |
Output is correct |
14 |
Correct |
131 ms |
12144 KB |
Output is correct |
15 |
Correct |
117 ms |
11776 KB |
Output is correct |
16 |
Correct |
228 ms |
11164 KB |
Output is correct |
17 |
Correct |
166 ms |
12592 KB |
Output is correct |
18 |
Correct |
267 ms |
12736 KB |
Output is correct |
19 |
Correct |
112 ms |
11620 KB |
Output is correct |
20 |
Correct |
212 ms |
11932 KB |
Output is correct |
21 |
Correct |
123 ms |
11800 KB |
Output is correct |
22 |
Correct |
119 ms |
10288 KB |
Output is correct |
23 |
Correct |
173 ms |
12956 KB |
Output is correct |
24 |
Correct |
142 ms |
12904 KB |
Output is correct |
25 |
Correct |
155 ms |
12756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
7892 KB |
Output is correct |
2 |
Correct |
34 ms |
7892 KB |
Output is correct |
3 |
Correct |
273 ms |
13032 KB |
Output is correct |
4 |
Correct |
265 ms |
12880 KB |
Output is correct |
5 |
Correct |
201 ms |
13196 KB |
Output is correct |
6 |
Correct |
265 ms |
13552 KB |
Output is correct |
7 |
Correct |
225 ms |
13248 KB |
Output is correct |
8 |
Correct |
309 ms |
13364 KB |
Output is correct |
9 |
Correct |
140 ms |
9896 KB |
Output is correct |
10 |
Correct |
295 ms |
11196 KB |
Output is correct |
11 |
Correct |
217 ms |
11624 KB |
Output is correct |
12 |
Correct |
335 ms |
13156 KB |
Output is correct |
13 |
Correct |
349 ms |
13304 KB |
Output is correct |
14 |
Correct |
214 ms |
13324 KB |
Output is correct |
15 |
Correct |
322 ms |
13564 KB |
Output is correct |
16 |
Correct |
202 ms |
12272 KB |
Output is correct |
17 |
Correct |
142 ms |
12860 KB |
Output is correct |
18 |
Correct |
124 ms |
11652 KB |
Output is correct |
19 |
Correct |
262 ms |
12940 KB |
Output is correct |
20 |
Correct |
180 ms |
12392 KB |
Output is correct |
21 |
Correct |
275 ms |
13656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
7880 KB |
Output is correct |
2 |
Correct |
28 ms |
8008 KB |
Output is correct |
3 |
Correct |
291 ms |
12828 KB |
Output is correct |
4 |
Correct |
204 ms |
12764 KB |
Output is correct |
5 |
Correct |
203 ms |
12976 KB |
Output is correct |
6 |
Correct |
266 ms |
13480 KB |
Output is correct |
7 |
Correct |
256 ms |
13136 KB |
Output is correct |
8 |
Correct |
185 ms |
13200 KB |
Output is correct |
9 |
Correct |
255 ms |
12936 KB |
Output is correct |
10 |
Correct |
312 ms |
13296 KB |
Output is correct |
11 |
Correct |
238 ms |
13384 KB |
Output is correct |
12 |
Correct |
343 ms |
13408 KB |
Output is correct |
13 |
Correct |
289 ms |
9912 KB |
Output is correct |
14 |
Correct |
162 ms |
10020 KB |
Output is correct |
15 |
Correct |
182 ms |
12344 KB |
Output is correct |
16 |
Correct |
147 ms |
11176 KB |
Output is correct |
17 |
Correct |
164 ms |
11644 KB |
Output is correct |
18 |
Correct |
178 ms |
11192 KB |
Output is correct |
19 |
Correct |
365 ms |
12824 KB |
Output is correct |
20 |
Correct |
215 ms |
13400 KB |
Output is correct |
21 |
Correct |
230 ms |
13348 KB |
Output is correct |
22 |
Correct |
229 ms |
13284 KB |
Output is correct |
23 |
Correct |
286 ms |
13340 KB |
Output is correct |
24 |
Correct |
217 ms |
13364 KB |
Output is correct |
25 |
Correct |
305 ms |
13504 KB |
Output is correct |
26 |
Correct |
317 ms |
13480 KB |
Output is correct |
27 |
Correct |
198 ms |
12188 KB |
Output is correct |
28 |
Correct |
225 ms |
12720 KB |
Output is correct |
29 |
Correct |
152 ms |
13600 KB |
Output is correct |
30 |
Correct |
229 ms |
13108 KB |
Output is correct |
31 |
Correct |
184 ms |
13180 KB |
Output is correct |
32 |
Correct |
206 ms |
13176 KB |
Output is correct |
33 |
Correct |
232 ms |
13608 KB |
Output is correct |
34 |
Correct |
250 ms |
12332 KB |
Output is correct |
35 |
Correct |
211 ms |
12668 KB |
Output is correct |
36 |
Correct |
144 ms |
13108 KB |
Output is correct |
37 |
Correct |
162 ms |
12980 KB |
Output is correct |
38 |
Correct |
225 ms |
13080 KB |
Output is correct |
39 |
Correct |
361 ms |
13632 KB |
Output is correct |
40 |
Correct |
227 ms |
13736 KB |
Output is correct |
41 |
Correct |
294 ms |
13784 KB |
Output is correct |
42 |
Correct |
370 ms |
13612 KB |
Output is correct |