#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define dl double long
const int maxn = 200100;
int m;
ll dist;
bool used[maxn];
int h[maxn];
int pa[maxn];
vector < int > nnj,f;
vector < pair < int , int > > v[maxn],g[maxn];
void dfs( int x , int p , int id )
{
h[x] = h[p] + 1;
f.push_back(x);
pa[x] = id;
for( auto y : g[x] ){
if( y.fi != p ){
dfs( y.fi , x , y.se );
}
}
}
int solve( int x )
{
f.clear();
h[x] = 0;
dfs( x , x , -1 );
vector < pair < int , int > > v;
for( int i = 0; i < (int)f.size(); i++ ){
v.push_back({ h[f[i]] , f[i] });
}
sort( v.rbegin() , v.rend() );
int l = 0 , r = (int)v.size() - 1;
int res = (int)v.size() - 1;
while( l <= r ){
int mi = (l + r) / 2;
vector < int > w(m , 0);
for( auto y : nnj ){
w[y] = 1;
}
for( int i = 0; i <= mi; i++ ){
if( pa[v[i].se] != -1 ){
w[pa[v[i].se]] = 1;
}
}
ll di = ask( w );
if( di > dist ){
res = min( res , mi );
r = mi - 1;
}else l = mi + 1;
}
return v[res].se;
}
void bfs( int x , int y )
{
vector < int > d(maxn , 1e9);
vector < int > p(maxn , -1);
d[x] = d[y] = 0;
queue < int > q;
q.push(x);
q.push(y);
while( !q.empty() ){
int x = q.front();
q.pop();
for( auto y : v[x] ){
if( d[y.fi] == 1e9 ){
d[y.fi] = d[x] + 1;
used[y.se] = true;
g[x].push_back(y);
g[y.fi].push_back({ x , y.se });
q.push(y.fi);
}
}
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
m = (int)U.size();
vector < int > a,b;
vector < int > w(m , 0);
dist = ask(w);
for( int i = 0; i < m; i++ ){
int x = U[i] , y = V[i];
v[x].push_back({y , i});
v[y].push_back({x , i});
}
int l = 0 , r = m - 1;
while( l < r ){
int mid = (l + r) / 2;
vector < int > w(m , 0);
for( int j = 0; j <= mid; j++ )w[j] = 1;
ll x = ask( w );
if( x == dist )l = mid + 1;
else r = mid;
}
bfs( U[l] , V[l] );
used[l] = true;
for( int i = 0; i < m; i++ ){
if( used[i] )continue;
nnj.push_back(i);
}
int ans1 = solve( U[l] );
int ans2 = solve( V[l] );
answer(ans1 , ans2);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11264 KB |
Output is correct |
2 |
Correct |
8 ms |
11264 KB |
Output is correct |
3 |
Correct |
9 ms |
11264 KB |
Output is correct |
4 |
Correct |
10 ms |
11264 KB |
Output is correct |
5 |
Correct |
8 ms |
11264 KB |
Output is correct |
6 |
Correct |
9 ms |
11264 KB |
Output is correct |
7 |
Correct |
9 ms |
11316 KB |
Output is correct |
8 |
Correct |
8 ms |
11264 KB |
Output is correct |
9 |
Correct |
8 ms |
11324 KB |
Output is correct |
10 |
Correct |
8 ms |
11264 KB |
Output is correct |
11 |
Correct |
10 ms |
11264 KB |
Output is correct |
12 |
Correct |
8 ms |
11264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11392 KB |
Output is correct |
2 |
Correct |
24 ms |
12288 KB |
Output is correct |
3 |
Correct |
208 ms |
21304 KB |
Output is correct |
4 |
Correct |
208 ms |
21164 KB |
Output is correct |
5 |
Correct |
204 ms |
21292 KB |
Output is correct |
6 |
Correct |
199 ms |
21228 KB |
Output is correct |
7 |
Correct |
217 ms |
21308 KB |
Output is correct |
8 |
Correct |
211 ms |
21184 KB |
Output is correct |
9 |
Correct |
202 ms |
21196 KB |
Output is correct |
10 |
Correct |
207 ms |
21228 KB |
Output is correct |
11 |
Correct |
244 ms |
20144 KB |
Output is correct |
12 |
Correct |
221 ms |
21052 KB |
Output is correct |
13 |
Correct |
217 ms |
21152 KB |
Output is correct |
14 |
Correct |
221 ms |
20852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
12152 KB |
Output is correct |
2 |
Correct |
38 ms |
12920 KB |
Output is correct |
3 |
Correct |
56 ms |
14496 KB |
Output is correct |
4 |
Correct |
146 ms |
22000 KB |
Output is correct |
5 |
Correct |
154 ms |
21912 KB |
Output is correct |
6 |
Correct |
152 ms |
23040 KB |
Output is correct |
7 |
Correct |
153 ms |
23760 KB |
Output is correct |
8 |
Correct |
156 ms |
22332 KB |
Output is correct |
9 |
Correct |
153 ms |
22624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11392 KB |
Output is correct |
2 |
Correct |
26 ms |
12288 KB |
Output is correct |
3 |
Correct |
154 ms |
19264 KB |
Output is correct |
4 |
Correct |
211 ms |
21180 KB |
Output is correct |
5 |
Correct |
205 ms |
21188 KB |
Output is correct |
6 |
Correct |
202 ms |
21176 KB |
Output is correct |
7 |
Correct |
205 ms |
21204 KB |
Output is correct |
8 |
Correct |
199 ms |
21176 KB |
Output is correct |
9 |
Correct |
222 ms |
21104 KB |
Output is correct |
10 |
Correct |
205 ms |
21224 KB |
Output is correct |
11 |
Correct |
218 ms |
20684 KB |
Output is correct |
12 |
Correct |
211 ms |
21100 KB |
Output is correct |
13 |
Correct |
224 ms |
20816 KB |
Output is correct |
14 |
Correct |
231 ms |
20408 KB |
Output is correct |
15 |
Correct |
204 ms |
21208 KB |
Output is correct |
16 |
Correct |
198 ms |
21196 KB |
Output is correct |
17 |
Correct |
231 ms |
20684 KB |
Output is correct |
18 |
Correct |
230 ms |
21040 KB |
Output is correct |
19 |
Correct |
206 ms |
21200 KB |
Output is correct |
20 |
Correct |
223 ms |
21328 KB |
Output is correct |
21 |
Correct |
181 ms |
21884 KB |
Output is correct |
22 |
Correct |
164 ms |
21892 KB |
Output is correct |
23 |
Correct |
180 ms |
21160 KB |
Output is correct |
24 |
Correct |
178 ms |
21248 KB |
Output is correct |
25 |
Correct |
194 ms |
23788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
12288 KB |
Output is correct |
2 |
Correct |
28 ms |
12288 KB |
Output is correct |
3 |
Correct |
238 ms |
21488 KB |
Output is correct |
4 |
Correct |
249 ms |
21744 KB |
Output is correct |
5 |
Correct |
293 ms |
22864 KB |
Output is correct |
6 |
Correct |
291 ms |
22520 KB |
Output is correct |
7 |
Correct |
295 ms |
22476 KB |
Output is correct |
8 |
Correct |
312 ms |
22472 KB |
Output is correct |
9 |
Correct |
195 ms |
18476 KB |
Output is correct |
10 |
Correct |
197 ms |
18816 KB |
Output is correct |
11 |
Correct |
219 ms |
19928 KB |
Output is correct |
12 |
Correct |
270 ms |
21396 KB |
Output is correct |
13 |
Correct |
288 ms |
21720 KB |
Output is correct |
14 |
Correct |
318 ms |
22108 KB |
Output is correct |
15 |
Correct |
283 ms |
22584 KB |
Output is correct |
16 |
Correct |
246 ms |
19628 KB |
Output is correct |
17 |
Correct |
176 ms |
22156 KB |
Output is correct |
18 |
Correct |
177 ms |
22156 KB |
Output is correct |
19 |
Correct |
177 ms |
22028 KB |
Output is correct |
20 |
Correct |
182 ms |
22224 KB |
Output is correct |
21 |
Correct |
323 ms |
23044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
12288 KB |
Output is correct |
2 |
Correct |
29 ms |
12288 KB |
Output is correct |
3 |
Correct |
254 ms |
20972 KB |
Output is correct |
4 |
Correct |
253 ms |
21240 KB |
Output is correct |
5 |
Correct |
260 ms |
21564 KB |
Output is correct |
6 |
Correct |
292 ms |
22688 KB |
Output is correct |
7 |
Correct |
228 ms |
21604 KB |
Output is correct |
8 |
Correct |
244 ms |
21704 KB |
Output is correct |
9 |
Correct |
253 ms |
21620 KB |
Output is correct |
10 |
Correct |
311 ms |
22388 KB |
Output is correct |
11 |
Correct |
293 ms |
22440 KB |
Output is correct |
12 |
Correct |
290 ms |
22520 KB |
Output is correct |
13 |
Correct |
215 ms |
19868 KB |
Output is correct |
14 |
Correct |
210 ms |
18796 KB |
Output is correct |
15 |
Correct |
198 ms |
19888 KB |
Output is correct |
16 |
Correct |
190 ms |
18676 KB |
Output is correct |
17 |
Correct |
205 ms |
19872 KB |
Output is correct |
18 |
Correct |
196 ms |
18916 KB |
Output is correct |
19 |
Correct |
280 ms |
21392 KB |
Output is correct |
20 |
Correct |
290 ms |
21960 KB |
Output is correct |
21 |
Correct |
319 ms |
22120 KB |
Output is correct |
22 |
Correct |
306 ms |
22080 KB |
Output is correct |
23 |
Correct |
312 ms |
22312 KB |
Output is correct |
24 |
Correct |
302 ms |
22204 KB |
Output is correct |
25 |
Correct |
285 ms |
22388 KB |
Output is correct |
26 |
Correct |
306 ms |
22484 KB |
Output is correct |
27 |
Correct |
178 ms |
22084 KB |
Output is correct |
28 |
Correct |
185 ms |
21960 KB |
Output is correct |
29 |
Correct |
179 ms |
22540 KB |
Output is correct |
30 |
Correct |
176 ms |
22152 KB |
Output is correct |
31 |
Correct |
176 ms |
22132 KB |
Output is correct |
32 |
Correct |
171 ms |
22032 KB |
Output is correct |
33 |
Correct |
189 ms |
22424 KB |
Output is correct |
34 |
Correct |
178 ms |
22116 KB |
Output is correct |
35 |
Correct |
174 ms |
22008 KB |
Output is correct |
36 |
Correct |
175 ms |
21860 KB |
Output is correct |
37 |
Correct |
175 ms |
22484 KB |
Output is correct |
38 |
Correct |
170 ms |
22284 KB |
Output is correct |
39 |
Correct |
304 ms |
23360 KB |
Output is correct |
40 |
Correct |
303 ms |
23216 KB |
Output is correct |
41 |
Correct |
281 ms |
22992 KB |
Output is correct |
42 |
Correct |
332 ms |
22616 KB |
Output is correct |