#include <bits/stdc++.h>
using namespace std ;
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define C continue
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long ll ;
typedef pair < int , int > pi ;
typedef vector < int > vi ;
typedef vector < pi > vpi ;
#include "highway.h"
ll n , X , Y , len ;
vi no ;
vpi v [100009] , ord ;
int lev [100009] ;
pi e [100009] ;
ll query ( vi ret ) {
vi xxx ( n - 1 , 0 ) ;
for ( auto u : ret ) {
xxx [u] = 1 ;
}
return ask ( xxx ) ;
}
//
void fill ( int node , int p , int crnt , int st , int val ) {
lev [node] = crnt ;
if ( st == node ) val = 1 ;
for ( auto u : v [node] ) {
if ( u .fi == p ) C ;
if ( val ) {
no .pb ( u.se ) ;
}
fill ( u .fi , node , crnt + 1 , st , val ) ;
}
}
bool cmp ( pi x , pi y ) {
return lev [x.fi] < lev [y.fi] ;
}
void dfs ( int node , int p , int crnt , int id ) {
lev [node] = crnt ;
if ( crnt ) {
ord .pb ( { node , id } ) ;
}
for ( auto u : v [node] ) {
if ( u.fi == p ) C ;
dfs ( u .fi , node , crnt + 1 , u.se ) ;
}
}
int solve ( int node , int p , int need ) {
if ( ! need ) return node ;
mem ( lev , 0 ) ;
ord .clear () ;
dfs ( node , p , 0 , - 1 ) ;
sort ( ord .begin () , ord .end () , cmp ) ;
int l = -1 , r = ord .size () - 1 ;
while ( r - l > 1 ) {
vi ret ;
for ( int i = mid + 1 ; i <= r ; i ++ ) {
ret .pb ( ord [i] .se ) ;
}
ll cost = query ( ret ) ;
if ( cost == len * X ) {
r = mid ;
}
else l = mid ;
}
return ord [r].fi ;
}
void find_pair ( int N, vi U, vi V, int A , int B ) {
n = N , X = A , Y = B ;
for ( int i = 0 ; i < n - 1 ; i ++ ) {
int a = U [i] , b = V [i] ;
v [a] .pb ( { b , i } ) ;
v [b] .pb ( { a , i } ) ;
e [i] = { a , b } ;
}
len = query ( no ) / A ;
int l = -1 , r = n -2 ;
while ( r - l > 1 ) {
vi ret ;
for ( int i = mid + 1 ; i <= r ; i ++ ) {
ret .pb ( i ) ;
}
ll cost = query ( ret ) ;
if ( cost == len * X ) {
r = mid ;
}
else l = mid ;
}
fill ( 0 , 0 , 0 , 0 , 0 ) ;
for ( int i = 0 ; i < n - 1 ; i ++ ) {
if ( lev [e[i].fi] > lev [e[i].se] ) {
swap ( e [i].fi , e [i] .se ) ;
}
}
no.clear () ;
fill ( 0 , 0 , 0 , e [r].se , 0 ) ;
ll crnt = query ( no ) ;
for ( ll i = 1 ; i <= len ; i ++ ) {
if ( i * A + ( len - i ) * B == crnt ) {
answer ( solve ( e [r].se , e [r] .fi , len - i ) , solve ( e [r] .fi , e [r] .se , i - 1 ) ) ;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3072 KB |
Output is correct |
2 |
Correct |
3 ms |
3072 KB |
Output is correct |
3 |
Correct |
3 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
3072 KB |
Output is correct |
5 |
Correct |
3 ms |
3072 KB |
Output is correct |
6 |
Correct |
4 ms |
3072 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
2 ms |
3104 KB |
Output is correct |
9 |
Correct |
3 ms |
3072 KB |
Output is correct |
10 |
Correct |
4 ms |
3072 KB |
Output is correct |
11 |
Correct |
2 ms |
3072 KB |
Output is correct |
12 |
Correct |
3 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3072 KB |
Output is correct |
2 |
Correct |
16 ms |
3880 KB |
Output is correct |
3 |
Correct |
181 ms |
10528 KB |
Output is correct |
4 |
Correct |
176 ms |
10536 KB |
Output is correct |
5 |
Correct |
156 ms |
10540 KB |
Output is correct |
6 |
Correct |
192 ms |
10536 KB |
Output is correct |
7 |
Correct |
170 ms |
10532 KB |
Output is correct |
8 |
Correct |
172 ms |
10520 KB |
Output is correct |
9 |
Correct |
173 ms |
10364 KB |
Output is correct |
10 |
Correct |
172 ms |
10548 KB |
Output is correct |
11 |
Correct |
189 ms |
11512 KB |
Output is correct |
12 |
Correct |
251 ms |
12836 KB |
Output is correct |
13 |
Correct |
199 ms |
12184 KB |
Output is correct |
14 |
Correct |
227 ms |
11556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
4736 KB |
Output is correct |
2 |
Correct |
27 ms |
6376 KB |
Output is correct |
3 |
Correct |
48 ms |
8132 KB |
Output is correct |
4 |
Correct |
125 ms |
17828 KB |
Output is correct |
5 |
Correct |
128 ms |
17668 KB |
Output is correct |
6 |
Correct |
132 ms |
18376 KB |
Output is correct |
7 |
Correct |
134 ms |
18356 KB |
Output is correct |
8 |
Correct |
176 ms |
17836 KB |
Output is correct |
9 |
Correct |
154 ms |
18344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3072 KB |
Output is correct |
2 |
Correct |
19 ms |
3960 KB |
Output is correct |
3 |
Correct |
123 ms |
9132 KB |
Output is correct |
4 |
Correct |
204 ms |
10512 KB |
Output is correct |
5 |
Correct |
161 ms |
9388 KB |
Output is correct |
6 |
Correct |
190 ms |
10520 KB |
Output is correct |
7 |
Correct |
208 ms |
10544 KB |
Output is correct |
8 |
Correct |
157 ms |
10516 KB |
Output is correct |
9 |
Correct |
169 ms |
10036 KB |
Output is correct |
10 |
Correct |
166 ms |
10656 KB |
Output is correct |
11 |
Correct |
183 ms |
11212 KB |
Output is correct |
12 |
Correct |
249 ms |
12928 KB |
Output is correct |
13 |
Correct |
214 ms |
11924 KB |
Output is correct |
14 |
Correct |
199 ms |
12496 KB |
Output is correct |
15 |
Correct |
161 ms |
10536 KB |
Output is correct |
16 |
Correct |
149 ms |
9376 KB |
Output is correct |
17 |
Correct |
203 ms |
12556 KB |
Output is correct |
18 |
Correct |
228 ms |
11948 KB |
Output is correct |
19 |
Correct |
161 ms |
10536 KB |
Output is correct |
20 |
Correct |
228 ms |
13640 KB |
Output is correct |
21 |
Correct |
148 ms |
10972 KB |
Output is correct |
22 |
Correct |
171 ms |
10840 KB |
Output is correct |
23 |
Correct |
168 ms |
10128 KB |
Output is correct |
24 |
Correct |
138 ms |
10892 KB |
Output is correct |
25 |
Correct |
230 ms |
17072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
3328 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
3328 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |