#include<bits/stdc++.h>
#include "highway.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10, inf = 1e9 + 10;
ll len;
vector<pii> v[maxn];
int h[maxn];
bool bad[maxn];
void bfs(int s){
queue<int> q;
q.push(s);
fill(h, h + maxn, inf);
h[s] = 0;
while(sz(q)){
int u = q.front();
q.pop();
for(auto [y, c] : v[u]){
if(h[y] == inf){
h[y] = h[u] + 1;
q.push(y);
}
}
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
int m = sz(U);
vector<int> w(m);
for(int i = 0; i < m; i++){
v[U[i]].PB({V[i], i});
v[V[i]].PB({U[i], i});
}
len = ask(w);
auto del = [&](int u){
for(auto [y, c] : v[u]){
w[c] = 1;
}
};
auto bin = [&](vector<int> vrts, function<bool(vector<int>)> f){
int l = 0, r = sz(vrts);
bool frs = 1;
while(r-l > 1){
int mid = (l+r) >> 1;
if(frs && mid > (1<<15) - 3)
mid = (1<<15) - 3;
frs = 0;
vector<int> vrts2;
for(int i = 0; i < mid; i++)
vrts2.PB(vrts[i]);
if(f(vrts2))
r = mid;
else
l = mid;
}
return vrts[l];
};
auto delete_and_ask = [&](vector<int> v){
for(int i = 0; i < N; i++){
if(bad[i])
v.PB(i);
}
for(int i = 0; i < m; i++)
w[i] = 0;
for(int u: v)
del(u);
return ask(w) != len;
};
vector<int> vrts(N), tmp;
auto erase_bads = [&](int root){
for(int x : vrts){
if(x == root)
break;
bad[x] = 1;
}
tmp = vrts;
vrts.clear();
for(int x : tmp){
if(!bad[x])
vrts.PB(x);
}
};
srand(time(0));
iota(vrts.begin(), vrts.end(), 0);
random_shuffle(vrts.begin(), vrts.end());
int root = bin(vrts, delete_and_ask);
erase_bads(root);
bfs(root);
sort(vrts.begin(), vrts.end(), [&](int i, int j){ return h[i] > h[j]; } );
int ans1 = bin(vrts, delete_and_ask);
erase_bads(ans1);
bfs(ans1);
sort(vrts.begin(), vrts.end(), [&](int i, int j){ return h[i] > h[j]; } );
int ans2 = bin(vrts, delete_and_ask);
answer(ans1, ans2);
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 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 |
3 ms |
3116 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
4 ms |
3072 KB |
Output is correct |
10 |
Correct |
3 ms |
3072 KB |
Output is correct |
11 |
Correct |
3 ms |
3072 KB |
Output is correct |
12 |
Correct |
3 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
47 ms |
3916 KB |
Output is correct |
3 |
Correct |
448 ms |
10468 KB |
Output is correct |
4 |
Correct |
348 ms |
9816 KB |
Output is correct |
5 |
Correct |
419 ms |
10092 KB |
Output is correct |
6 |
Correct |
259 ms |
9800 KB |
Output is correct |
7 |
Correct |
433 ms |
10488 KB |
Output is correct |
8 |
Correct |
444 ms |
10724 KB |
Output is correct |
9 |
Correct |
450 ms |
10672 KB |
Output is correct |
10 |
Correct |
363 ms |
10104 KB |
Output is correct |
11 |
Correct |
476 ms |
10096 KB |
Output is correct |
12 |
Correct |
425 ms |
9540 KB |
Output is correct |
13 |
Correct |
412 ms |
9896 KB |
Output is correct |
14 |
Correct |
406 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
3896 KB |
Output is correct |
2 |
Correct |
66 ms |
4520 KB |
Output is correct |
3 |
Correct |
58 ms |
5460 KB |
Output is correct |
4 |
Correct |
192 ms |
9872 KB |
Output is correct |
5 |
Correct |
195 ms |
10072 KB |
Output is correct |
6 |
Correct |
169 ms |
9176 KB |
Output is correct |
7 |
Correct |
195 ms |
10104 KB |
Output is correct |
8 |
Correct |
185 ms |
9412 KB |
Output is correct |
9 |
Correct |
183 ms |
9660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
24 ms |
3968 KB |
Output is correct |
3 |
Correct |
333 ms |
8928 KB |
Output is correct |
4 |
Correct |
463 ms |
10748 KB |
Output is correct |
5 |
Correct |
451 ms |
10736 KB |
Output is correct |
6 |
Correct |
461 ms |
10792 KB |
Output is correct |
7 |
Correct |
456 ms |
10484 KB |
Output is correct |
8 |
Correct |
438 ms |
10760 KB |
Output is correct |
9 |
Correct |
407 ms |
10252 KB |
Output is correct |
10 |
Correct |
477 ms |
10116 KB |
Output is correct |
11 |
Correct |
419 ms |
9440 KB |
Output is correct |
12 |
Correct |
278 ms |
9456 KB |
Output is correct |
13 |
Correct |
403 ms |
9632 KB |
Output is correct |
14 |
Correct |
430 ms |
9516 KB |
Output is correct |
15 |
Correct |
474 ms |
10620 KB |
Output is correct |
16 |
Correct |
461 ms |
10180 KB |
Output is correct |
17 |
Correct |
357 ms |
9276 KB |
Output is correct |
18 |
Correct |
424 ms |
10028 KB |
Output is correct |
19 |
Correct |
401 ms |
10748 KB |
Output is correct |
20 |
Correct |
436 ms |
10188 KB |
Output is correct |
21 |
Correct |
411 ms |
10628 KB |
Output is correct |
22 |
Correct |
399 ms |
10340 KB |
Output is correct |
23 |
Correct |
313 ms |
9968 KB |
Output is correct |
24 |
Correct |
271 ms |
9956 KB |
Output is correct |
25 |
Correct |
230 ms |
9416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
3832 KB |
Output is correct |
2 |
Correct |
27 ms |
4016 KB |
Output is correct |
3 |
Correct |
377 ms |
10360 KB |
Output is correct |
4 |
Correct |
536 ms |
11516 KB |
Output is correct |
5 |
Correct |
586 ms |
12280 KB |
Output is correct |
6 |
Correct |
524 ms |
11768 KB |
Output is correct |
7 |
Correct |
603 ms |
12280 KB |
Output is correct |
8 |
Correct |
349 ms |
11532 KB |
Output is correct |
9 |
Correct |
257 ms |
9072 KB |
Output is correct |
10 |
Correct |
280 ms |
9668 KB |
Output is correct |
11 |
Correct |
302 ms |
9992 KB |
Output is correct |
12 |
Correct |
549 ms |
11532 KB |
Output is correct |
13 |
Correct |
551 ms |
11760 KB |
Output is correct |
14 |
Correct |
391 ms |
11704 KB |
Output is correct |
15 |
Correct |
569 ms |
11860 KB |
Output is correct |
16 |
Correct |
406 ms |
10336 KB |
Output is correct |
17 |
Correct |
388 ms |
10456 KB |
Output is correct |
18 |
Correct |
352 ms |
10396 KB |
Output is correct |
19 |
Correct |
370 ms |
10504 KB |
Output is correct |
20 |
Correct |
424 ms |
10412 KB |
Output is correct |
21 |
Correct |
586 ms |
12504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
3984 KB |
Output is correct |
2 |
Correct |
27 ms |
3976 KB |
Output is correct |
3 |
Correct |
575 ms |
11052 KB |
Output is correct |
4 |
Correct |
468 ms |
10496 KB |
Output is correct |
5 |
Correct |
557 ms |
11080 KB |
Output is correct |
6 |
Correct |
457 ms |
11752 KB |
Output is correct |
7 |
Correct |
521 ms |
10948 KB |
Output is correct |
8 |
Correct |
508 ms |
11408 KB |
Output is correct |
9 |
Correct |
544 ms |
11420 KB |
Output is correct |
10 |
Correct |
531 ms |
11840 KB |
Output is correct |
11 |
Correct |
486 ms |
11788 KB |
Output is correct |
12 |
Correct |
530 ms |
11768 KB |
Output is correct |
13 |
Correct |
297 ms |
9932 KB |
Output is correct |
14 |
Correct |
271 ms |
9532 KB |
Output is correct |
15 |
Correct |
292 ms |
10276 KB |
Output is correct |
16 |
Correct |
247 ms |
9920 KB |
Output is correct |
17 |
Correct |
341 ms |
10072 KB |
Output is correct |
18 |
Correct |
282 ms |
9676 KB |
Output is correct |
19 |
Correct |
487 ms |
12112 KB |
Output is correct |
20 |
Correct |
504 ms |
12076 KB |
Output is correct |
21 |
Correct |
597 ms |
12384 KB |
Output is correct |
22 |
Correct |
641 ms |
12304 KB |
Output is correct |
23 |
Correct |
614 ms |
12020 KB |
Output is correct |
24 |
Correct |
611 ms |
12404 KB |
Output is correct |
25 |
Correct |
551 ms |
11824 KB |
Output is correct |
26 |
Correct |
546 ms |
11908 KB |
Output is correct |
27 |
Correct |
331 ms |
10364 KB |
Output is correct |
28 |
Correct |
303 ms |
10100 KB |
Output is correct |
29 |
Correct |
419 ms |
11236 KB |
Output is correct |
30 |
Correct |
405 ms |
10584 KB |
Output is correct |
31 |
Correct |
304 ms |
10176 KB |
Output is correct |
32 |
Correct |
401 ms |
10808 KB |
Output is correct |
33 |
Correct |
412 ms |
11028 KB |
Output is correct |
34 |
Correct |
327 ms |
10184 KB |
Output is correct |
35 |
Correct |
390 ms |
10452 KB |
Output is correct |
36 |
Correct |
422 ms |
10492 KB |
Output is correct |
37 |
Correct |
292 ms |
10432 KB |
Output is correct |
38 |
Correct |
485 ms |
10324 KB |
Output is correct |
39 |
Correct |
578 ms |
12392 KB |
Output is correct |
40 |
Correct |
561 ms |
12316 KB |
Output is correct |
41 |
Correct |
318 ms |
11736 KB |
Output is correct |
42 |
Correct |
585 ms |
12524 KB |
Output is correct |