#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=100050;
ll dist;
vector<pair<int,int>> E[N];
vector<int> I[N];
int d[N],f[N];
void AddEdge(int u, int v, int id){ E[u].pb(mp(v,id));E[v].pb(mp(u,id));}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B)
{
int m=U.size();
int top=m-1,bot=0,mid,ans;
vector<int> use(m,0);
dist=ask(use);
while(top>=bot)
{
mid=top+bot>>1;
use.clear();use.resize(m);
for(int i=0;i<=mid;i++) use[i]=1;
if(ask(use)==dist) bot=mid+1;
else ans=mid,top=mid-1;
}
for(int i=ans+1;i<m;i++) AddEdge(U[i],V[i],i);
queue<int> q;q.push(U[ans]);q.push(V[ans]);
d[U[ans]]=d[V[ans]]=1;
f[U[ans]]=1;f[V[ans]]=2;
vector<int> L,R;
while(q.size())
{
int x=q.front();q.pop();
if(f[x]&1) L.pb(x);
if(f[x]&2) R.pb(x);
for(auto e:E[x])
{
int y=e.first;
int id=e.second;
if(!d[y]) d[y]=d[x]+1,f[y]=f[x],q.push(y);
if(d[y]==d[x]+1) I[y].pb(id),f[y]|=f[x];
}
}
int bad=-1;
auto Solve=[&](vector<int> vs)
{
top=(int)vs.size()-1;bot=0;
int ret=vs[0];
vector<int> use;
while(top>=bot)
{
mid=top+bot>>1;
use.clear();use.resize(m);
for(int i=0;i<ans;i++) use[i]=1;
for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1;
if(ask(use)==dist) top=mid-1;
else ret=vs[mid],bot=mid+1;
}
bad=ret;
return ret;
};
return answer(Solve(L),Solve(R));
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:21:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid=top+bot>>1;
~~~^~~~
highway.cpp: In lambda function:
highway.cpp:53:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid=top+bot>>1;
~~~^~~~
highway.cpp:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1;
~^~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:28:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
queue<int> q;q.push(U[ans]);q.push(V[ans]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
5020 KB |
Output is correct |
3 |
Correct |
6 ms |
5064 KB |
Output is correct |
4 |
Correct |
5 ms |
5032 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
5028 KB |
Output is correct |
7 |
Correct |
6 ms |
5060 KB |
Output is correct |
8 |
Correct |
6 ms |
5024 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5024 KB |
Output is correct |
11 |
Correct |
6 ms |
5024 KB |
Output is correct |
12 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5040 KB |
Output is correct |
2 |
Correct |
33 ms |
6120 KB |
Output is correct |
3 |
Correct |
264 ms |
13944 KB |
Output is correct |
4 |
Correct |
234 ms |
13828 KB |
Output is correct |
5 |
Correct |
270 ms |
14716 KB |
Output is correct |
6 |
Correct |
174 ms |
12940 KB |
Output is correct |
7 |
Correct |
212 ms |
12668 KB |
Output is correct |
8 |
Correct |
294 ms |
14768 KB |
Output is correct |
9 |
Correct |
225 ms |
12708 KB |
Output is correct |
10 |
Correct |
255 ms |
13708 KB |
Output is correct |
11 |
Correct |
188 ms |
11088 KB |
Output is correct |
12 |
Correct |
317 ms |
13896 KB |
Output is correct |
13 |
Correct |
294 ms |
14104 KB |
Output is correct |
14 |
Correct |
297 ms |
14316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
5864 KB |
Output is correct |
2 |
Correct |
45 ms |
6780 KB |
Output is correct |
3 |
Correct |
42 ms |
6016 KB |
Output is correct |
4 |
Correct |
161 ms |
11540 KB |
Output is correct |
5 |
Correct |
160 ms |
11588 KB |
Output is correct |
6 |
Correct |
164 ms |
12884 KB |
Output is correct |
7 |
Correct |
135 ms |
7564 KB |
Output is correct |
8 |
Correct |
178 ms |
12300 KB |
Output is correct |
9 |
Correct |
171 ms |
8968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5032 KB |
Output is correct |
2 |
Correct |
45 ms |
6048 KB |
Output is correct |
3 |
Correct |
231 ms |
12588 KB |
Output is correct |
4 |
Correct |
339 ms |
13776 KB |
Output is correct |
5 |
Correct |
230 ms |
10772 KB |
Output is correct |
6 |
Correct |
161 ms |
11124 KB |
Output is correct |
7 |
Correct |
234 ms |
12548 KB |
Output is correct |
8 |
Correct |
183 ms |
11184 KB |
Output is correct |
9 |
Correct |
286 ms |
14200 KB |
Output is correct |
10 |
Correct |
239 ms |
13236 KB |
Output is correct |
11 |
Correct |
288 ms |
14004 KB |
Output is correct |
12 |
Correct |
254 ms |
13676 KB |
Output is correct |
13 |
Correct |
282 ms |
13164 KB |
Output is correct |
14 |
Correct |
190 ms |
11480 KB |
Output is correct |
15 |
Correct |
165 ms |
10904 KB |
Output is correct |
16 |
Correct |
172 ms |
9492 KB |
Output is correct |
17 |
Correct |
303 ms |
13672 KB |
Output is correct |
18 |
Correct |
287 ms |
14232 KB |
Output is correct |
19 |
Correct |
168 ms |
10356 KB |
Output is correct |
20 |
Correct |
185 ms |
10752 KB |
Output is correct |
21 |
Correct |
231 ms |
12364 KB |
Output is correct |
22 |
Correct |
192 ms |
9812 KB |
Output is correct |
23 |
Correct |
242 ms |
15172 KB |
Output is correct |
24 |
Correct |
225 ms |
15192 KB |
Output is correct |
25 |
Correct |
251 ms |
14344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
6184 KB |
Output is correct |
2 |
Correct |
27 ms |
6056 KB |
Output is correct |
3 |
Correct |
278 ms |
15092 KB |
Output is correct |
4 |
Correct |
360 ms |
14536 KB |
Output is correct |
5 |
Correct |
383 ms |
15020 KB |
Output is correct |
6 |
Correct |
489 ms |
16448 KB |
Output is correct |
7 |
Correct |
455 ms |
15740 KB |
Output is correct |
8 |
Correct |
389 ms |
15196 KB |
Output is correct |
9 |
Correct |
216 ms |
8372 KB |
Output is correct |
10 |
Correct |
229 ms |
10648 KB |
Output is correct |
11 |
Correct |
271 ms |
11648 KB |
Output is correct |
12 |
Correct |
457 ms |
15344 KB |
Output is correct |
13 |
Correct |
507 ms |
15828 KB |
Output is correct |
14 |
Correct |
483 ms |
16308 KB |
Output is correct |
15 |
Correct |
503 ms |
16252 KB |
Output is correct |
16 |
Correct |
356 ms |
13332 KB |
Output is correct |
17 |
Correct |
207 ms |
14004 KB |
Output is correct |
18 |
Correct |
185 ms |
11004 KB |
Output is correct |
19 |
Correct |
220 ms |
14492 KB |
Output is correct |
20 |
Correct |
180 ms |
12680 KB |
Output is correct |
21 |
Correct |
414 ms |
16436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
6120 KB |
Output is correct |
2 |
Correct |
32 ms |
6164 KB |
Output is correct |
3 |
Correct |
382 ms |
15348 KB |
Output is correct |
4 |
Correct |
375 ms |
15168 KB |
Output is correct |
5 |
Correct |
417 ms |
15104 KB |
Output is correct |
6 |
Correct |
453 ms |
15880 KB |
Output is correct |
7 |
Correct |
321 ms |
15120 KB |
Output is correct |
8 |
Correct |
371 ms |
15396 KB |
Output is correct |
9 |
Correct |
372 ms |
14936 KB |
Output is correct |
10 |
Correct |
503 ms |
15956 KB |
Output is correct |
11 |
Correct |
510 ms |
16564 KB |
Output is correct |
12 |
Correct |
461 ms |
16012 KB |
Output is correct |
13 |
Correct |
232 ms |
8500 KB |
Output is correct |
14 |
Correct |
234 ms |
8360 KB |
Output is correct |
15 |
Correct |
321 ms |
13236 KB |
Output is correct |
16 |
Correct |
254 ms |
10652 KB |
Output is correct |
17 |
Correct |
276 ms |
11696 KB |
Output is correct |
18 |
Correct |
275 ms |
10776 KB |
Output is correct |
19 |
Correct |
454 ms |
14976 KB |
Output is correct |
20 |
Correct |
504 ms |
15872 KB |
Output is correct |
21 |
Correct |
519 ms |
16320 KB |
Output is correct |
22 |
Correct |
484 ms |
16048 KB |
Output is correct |
23 |
Correct |
513 ms |
16284 KB |
Output is correct |
24 |
Correct |
480 ms |
16404 KB |
Output is correct |
25 |
Correct |
430 ms |
15912 KB |
Output is correct |
26 |
Correct |
487 ms |
16252 KB |
Output is correct |
27 |
Correct |
225 ms |
12484 KB |
Output is correct |
28 |
Correct |
273 ms |
14056 KB |
Output is correct |
29 |
Correct |
279 ms |
15540 KB |
Output is correct |
30 |
Correct |
266 ms |
15044 KB |
Output is correct |
31 |
Correct |
260 ms |
14504 KB |
Output is correct |
32 |
Correct |
280 ms |
14552 KB |
Output is correct |
33 |
Correct |
239 ms |
15832 KB |
Output is correct |
34 |
Correct |
219 ms |
13256 KB |
Output is correct |
35 |
Correct |
194 ms |
13980 KB |
Output is correct |
36 |
Correct |
292 ms |
14804 KB |
Output is correct |
37 |
Correct |
268 ms |
14380 KB |
Output is correct |
38 |
Correct |
235 ms |
14660 KB |
Output is correct |
39 |
Correct |
421 ms |
16368 KB |
Output is correct |
40 |
Correct |
401 ms |
16376 KB |
Output is correct |
41 |
Correct |
313 ms |
16400 KB |
Output is correct |
42 |
Correct |
456 ms |
16364 KB |
Output is correct |