#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
int tim;
int p[300200];
int s[300200];
int su[300200];
int t1[300200];
int t2[300200];
int tin[300200];
int tout[300200];
int st;
int cnt[300200];
int up[300200][25];
int can[300200][25];
vector < int > v[300200];
int get2( int x )
{
return (p[x] == x ? x : p[x] = get2(p[x]));
}
void merg( int x , int y , int w )
{
cnt[x] += 1 , cnt[y] += 1;
int px = get2( x );
int py = get2( y );
su[st] = w;
if( cnt[x] >= 3 || cnt[y] >= 3 )t1[st] = 1;
if( px == py ){
v[st].push_back(px);
t1[st] |= t1[px];
t2[st] = t2[px] + 1;
s[st] = s[px];
p[px] = st;
}else{
t2[st] = t2[px] + t2[py] + 1;
s[st] = s[px] + s[py];
t1[st] |= (t1[px] | t1[py]);
v[st].push_back(px);
v[st].push_back(py);
p[py] = st;
p[px] = st;
}
st += 1;
}
void dfs( int x , int p )
{
tin[x] = ++tim;
up[x][0] = p;
if( t2[x] >= s[x] ){
t2[x] = 1;
}else t2[x] = 0;
can[x][0] = (t1[p] | t2[p]);
for( int i = 1; i < 25; i++ ){
up[x][i] = up[up[x][i - 1]][i - 1];
can[x][i] = (can[x][i - 1] | can[up[x][i - 1]][i - 1]);
}
for( auto y : v[x] ){
if( y == p )continue;
dfs( y , x );
}
tout[x] = tim;
}
bool upper( int x , int y )
{
return (tin[x] <= tin[y] && tout[y] <= tout[x]);
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W)
{
st = N;
vector < int > ord;
for( int i = 0; i < M; i++ ){
ord.push_back(i);
}
for( int i = 0; i < 200200; i++ ){
p[i] = i;
s[i] = 1;
}
sort( ord.begin() , ord.end() , [&](int i , int j){
return W[i] < W[j];
});
for( int i = 0; i < M; i++ ){
merg( U[ord[i]] , V[ord[i]] , W[ord[i]] );
}
st -= 1;
dfs( st , st );
}
int get( int x , int y )
{
if( upper( x , y ) )return x;
if( upper( y , x ) )return y;
for( int i = 24; i >= 0; i-- ){
if( !upper( up[x][i] , y ) ){
x = up[x][i];
}
}
return up[x][0];
}
int get1( int x )
{
for( int i = 24; i >= 0; i-- ){
if( !can[x][i] ){
x = up[x][i];
}
}
return up[x][0];
}
int getMinimumFuelCapacity(int X, int Y)
{
if( (t1[st] | t2[st]) == 0 ){
return -1;
}
int f = get( X , Y );
if( (t1[f] | t2[f]) ){
return su[f];
}else{
return su[get1( f )];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
7 ms |
9216 KB |
Output is correct |
5 |
Correct |
7 ms |
9472 KB |
Output is correct |
6 |
Correct |
8 ms |
9472 KB |
Output is correct |
7 |
Correct |
8 ms |
9472 KB |
Output is correct |
8 |
Correct |
7 ms |
9472 KB |
Output is correct |
9 |
Correct |
150 ms |
47088 KB |
Output is correct |
10 |
Correct |
181 ms |
55660 KB |
Output is correct |
11 |
Correct |
185 ms |
54768 KB |
Output is correct |
12 |
Correct |
193 ms |
57456 KB |
Output is correct |
13 |
Correct |
216 ms |
60016 KB |
Output is correct |
14 |
Correct |
155 ms |
47216 KB |
Output is correct |
15 |
Correct |
263 ms |
57616 KB |
Output is correct |
16 |
Correct |
260 ms |
56176 KB |
Output is correct |
17 |
Correct |
267 ms |
59200 KB |
Output is correct |
18 |
Correct |
290 ms |
61424 KB |
Output is correct |
19 |
Correct |
146 ms |
20192 KB |
Output is correct |
20 |
Correct |
336 ms |
58732 KB |
Output is correct |
21 |
Correct |
339 ms |
57196 KB |
Output is correct |
22 |
Correct |
357 ms |
60492 KB |
Output is correct |
23 |
Correct |
528 ms |
62704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
425 ms |
62236 KB |
Output is correct |
4 |
Correct |
412 ms |
64720 KB |
Output is correct |
5 |
Correct |
422 ms |
62988 KB |
Output is correct |
6 |
Correct |
413 ms |
64476 KB |
Output is correct |
7 |
Correct |
450 ms |
63904 KB |
Output is correct |
8 |
Correct |
430 ms |
61612 KB |
Output is correct |
9 |
Correct |
418 ms |
63468 KB |
Output is correct |
10 |
Correct |
413 ms |
61116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
7 ms |
9216 KB |
Output is correct |
6 |
Correct |
7 ms |
9472 KB |
Output is correct |
7 |
Correct |
8 ms |
9472 KB |
Output is correct |
8 |
Correct |
8 ms |
9472 KB |
Output is correct |
9 |
Correct |
7 ms |
9472 KB |
Output is correct |
10 |
Correct |
8 ms |
9472 KB |
Output is correct |
11 |
Correct |
7 ms |
9472 KB |
Output is correct |
12 |
Correct |
7 ms |
9472 KB |
Output is correct |
13 |
Correct |
7 ms |
9344 KB |
Output is correct |
14 |
Correct |
8 ms |
9344 KB |
Output is correct |
15 |
Correct |
7 ms |
9472 KB |
Output is correct |
16 |
Correct |
7 ms |
9472 KB |
Output is correct |
17 |
Correct |
8 ms |
9472 KB |
Output is correct |
18 |
Correct |
8 ms |
9472 KB |
Output is correct |
19 |
Correct |
8 ms |
9472 KB |
Output is correct |
20 |
Correct |
7 ms |
9472 KB |
Output is correct |
21 |
Correct |
8 ms |
9472 KB |
Output is correct |
22 |
Correct |
8 ms |
9600 KB |
Output is correct |
23 |
Correct |
7 ms |
9344 KB |
Output is correct |
24 |
Correct |
9 ms |
9728 KB |
Output is correct |
25 |
Correct |
8 ms |
9728 KB |
Output is correct |
26 |
Correct |
8 ms |
9728 KB |
Output is correct |
27 |
Correct |
7 ms |
9472 KB |
Output is correct |
28 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
7 ms |
9216 KB |
Output is correct |
6 |
Correct |
7 ms |
9472 KB |
Output is correct |
7 |
Correct |
8 ms |
9472 KB |
Output is correct |
8 |
Correct |
8 ms |
9472 KB |
Output is correct |
9 |
Correct |
7 ms |
9472 KB |
Output is correct |
10 |
Correct |
150 ms |
47088 KB |
Output is correct |
11 |
Correct |
181 ms |
55660 KB |
Output is correct |
12 |
Correct |
185 ms |
54768 KB |
Output is correct |
13 |
Correct |
193 ms |
57456 KB |
Output is correct |
14 |
Correct |
216 ms |
60016 KB |
Output is correct |
15 |
Correct |
8 ms |
9472 KB |
Output is correct |
16 |
Correct |
7 ms |
9472 KB |
Output is correct |
17 |
Correct |
7 ms |
9472 KB |
Output is correct |
18 |
Correct |
7 ms |
9344 KB |
Output is correct |
19 |
Correct |
8 ms |
9344 KB |
Output is correct |
20 |
Correct |
7 ms |
9472 KB |
Output is correct |
21 |
Correct |
7 ms |
9472 KB |
Output is correct |
22 |
Correct |
8 ms |
9472 KB |
Output is correct |
23 |
Correct |
8 ms |
9472 KB |
Output is correct |
24 |
Correct |
27 ms |
15616 KB |
Output is correct |
25 |
Correct |
189 ms |
57460 KB |
Output is correct |
26 |
Correct |
189 ms |
57456 KB |
Output is correct |
27 |
Correct |
196 ms |
57460 KB |
Output is correct |
28 |
Correct |
195 ms |
56816 KB |
Output is correct |
29 |
Correct |
189 ms |
56560 KB |
Output is correct |
30 |
Correct |
168 ms |
52592 KB |
Output is correct |
31 |
Correct |
189 ms |
57456 KB |
Output is correct |
32 |
Correct |
190 ms |
57456 KB |
Output is correct |
33 |
Correct |
211 ms |
60656 KB |
Output is correct |
34 |
Correct |
196 ms |
57584 KB |
Output is correct |
35 |
Correct |
8 ms |
9472 KB |
Output is correct |
36 |
Correct |
7 ms |
9472 KB |
Output is correct |
37 |
Correct |
8 ms |
9472 KB |
Output is correct |
38 |
Correct |
8 ms |
9600 KB |
Output is correct |
39 |
Correct |
7 ms |
9344 KB |
Output is correct |
40 |
Correct |
9 ms |
9728 KB |
Output is correct |
41 |
Correct |
8 ms |
9728 KB |
Output is correct |
42 |
Correct |
8 ms |
9728 KB |
Output is correct |
43 |
Correct |
7 ms |
9472 KB |
Output is correct |
44 |
Correct |
9 ms |
9728 KB |
Output is correct |
45 |
Runtime error |
484 ms |
524288 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
7 ms |
9216 KB |
Output is correct |
5 |
Correct |
7 ms |
9472 KB |
Output is correct |
6 |
Correct |
8 ms |
9472 KB |
Output is correct |
7 |
Correct |
8 ms |
9472 KB |
Output is correct |
8 |
Correct |
7 ms |
9472 KB |
Output is correct |
9 |
Correct |
150 ms |
47088 KB |
Output is correct |
10 |
Correct |
181 ms |
55660 KB |
Output is correct |
11 |
Correct |
185 ms |
54768 KB |
Output is correct |
12 |
Correct |
193 ms |
57456 KB |
Output is correct |
13 |
Correct |
216 ms |
60016 KB |
Output is correct |
14 |
Correct |
155 ms |
47216 KB |
Output is correct |
15 |
Correct |
263 ms |
57616 KB |
Output is correct |
16 |
Correct |
260 ms |
56176 KB |
Output is correct |
17 |
Correct |
267 ms |
59200 KB |
Output is correct |
18 |
Correct |
290 ms |
61424 KB |
Output is correct |
19 |
Correct |
425 ms |
62236 KB |
Output is correct |
20 |
Correct |
412 ms |
64720 KB |
Output is correct |
21 |
Correct |
422 ms |
62988 KB |
Output is correct |
22 |
Correct |
413 ms |
64476 KB |
Output is correct |
23 |
Correct |
450 ms |
63904 KB |
Output is correct |
24 |
Correct |
430 ms |
61612 KB |
Output is correct |
25 |
Correct |
418 ms |
63468 KB |
Output is correct |
26 |
Correct |
413 ms |
61116 KB |
Output is correct |
27 |
Correct |
8 ms |
9472 KB |
Output is correct |
28 |
Correct |
7 ms |
9472 KB |
Output is correct |
29 |
Correct |
7 ms |
9472 KB |
Output is correct |
30 |
Correct |
7 ms |
9344 KB |
Output is correct |
31 |
Correct |
8 ms |
9344 KB |
Output is correct |
32 |
Correct |
7 ms |
9472 KB |
Output is correct |
33 |
Correct |
7 ms |
9472 KB |
Output is correct |
34 |
Correct |
8 ms |
9472 KB |
Output is correct |
35 |
Correct |
8 ms |
9472 KB |
Output is correct |
36 |
Correct |
27 ms |
15616 KB |
Output is correct |
37 |
Correct |
189 ms |
57460 KB |
Output is correct |
38 |
Correct |
189 ms |
57456 KB |
Output is correct |
39 |
Correct |
196 ms |
57460 KB |
Output is correct |
40 |
Correct |
195 ms |
56816 KB |
Output is correct |
41 |
Correct |
189 ms |
56560 KB |
Output is correct |
42 |
Correct |
168 ms |
52592 KB |
Output is correct |
43 |
Correct |
189 ms |
57456 KB |
Output is correct |
44 |
Correct |
190 ms |
57456 KB |
Output is correct |
45 |
Correct |
211 ms |
60656 KB |
Output is correct |
46 |
Correct |
196 ms |
57584 KB |
Output is correct |
47 |
Correct |
38 ms |
15352 KB |
Output is correct |
48 |
Correct |
342 ms |
59892 KB |
Output is correct |
49 |
Correct |
334 ms |
59808 KB |
Output is correct |
50 |
Correct |
342 ms |
59856 KB |
Output is correct |
51 |
Correct |
335 ms |
59416 KB |
Output is correct |
52 |
Correct |
326 ms |
56716 KB |
Output is correct |
53 |
Correct |
284 ms |
44380 KB |
Output is correct |
54 |
Correct |
343 ms |
60364 KB |
Output is correct |
55 |
Correct |
344 ms |
59668 KB |
Output is correct |
56 |
Correct |
445 ms |
62284 KB |
Output is correct |
57 |
Correct |
360 ms |
60396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
7 ms |
9216 KB |
Output is correct |
6 |
Correct |
7 ms |
9472 KB |
Output is correct |
7 |
Correct |
8 ms |
9472 KB |
Output is correct |
8 |
Correct |
8 ms |
9472 KB |
Output is correct |
9 |
Correct |
7 ms |
9472 KB |
Output is correct |
10 |
Correct |
150 ms |
47088 KB |
Output is correct |
11 |
Correct |
181 ms |
55660 KB |
Output is correct |
12 |
Correct |
185 ms |
54768 KB |
Output is correct |
13 |
Correct |
193 ms |
57456 KB |
Output is correct |
14 |
Correct |
216 ms |
60016 KB |
Output is correct |
15 |
Correct |
155 ms |
47216 KB |
Output is correct |
16 |
Correct |
263 ms |
57616 KB |
Output is correct |
17 |
Correct |
260 ms |
56176 KB |
Output is correct |
18 |
Correct |
267 ms |
59200 KB |
Output is correct |
19 |
Correct |
290 ms |
61424 KB |
Output is correct |
20 |
Correct |
425 ms |
62236 KB |
Output is correct |
21 |
Correct |
412 ms |
64720 KB |
Output is correct |
22 |
Correct |
422 ms |
62988 KB |
Output is correct |
23 |
Correct |
413 ms |
64476 KB |
Output is correct |
24 |
Correct |
450 ms |
63904 KB |
Output is correct |
25 |
Correct |
430 ms |
61612 KB |
Output is correct |
26 |
Correct |
418 ms |
63468 KB |
Output is correct |
27 |
Correct |
413 ms |
61116 KB |
Output is correct |
28 |
Correct |
8 ms |
9472 KB |
Output is correct |
29 |
Correct |
7 ms |
9472 KB |
Output is correct |
30 |
Correct |
7 ms |
9472 KB |
Output is correct |
31 |
Correct |
7 ms |
9344 KB |
Output is correct |
32 |
Correct |
8 ms |
9344 KB |
Output is correct |
33 |
Correct |
7 ms |
9472 KB |
Output is correct |
34 |
Correct |
7 ms |
9472 KB |
Output is correct |
35 |
Correct |
8 ms |
9472 KB |
Output is correct |
36 |
Correct |
8 ms |
9472 KB |
Output is correct |
37 |
Correct |
27 ms |
15616 KB |
Output is correct |
38 |
Correct |
189 ms |
57460 KB |
Output is correct |
39 |
Correct |
189 ms |
57456 KB |
Output is correct |
40 |
Correct |
196 ms |
57460 KB |
Output is correct |
41 |
Correct |
195 ms |
56816 KB |
Output is correct |
42 |
Correct |
189 ms |
56560 KB |
Output is correct |
43 |
Correct |
168 ms |
52592 KB |
Output is correct |
44 |
Correct |
189 ms |
57456 KB |
Output is correct |
45 |
Correct |
190 ms |
57456 KB |
Output is correct |
46 |
Correct |
211 ms |
60656 KB |
Output is correct |
47 |
Correct |
196 ms |
57584 KB |
Output is correct |
48 |
Correct |
38 ms |
15352 KB |
Output is correct |
49 |
Correct |
342 ms |
59892 KB |
Output is correct |
50 |
Correct |
334 ms |
59808 KB |
Output is correct |
51 |
Correct |
342 ms |
59856 KB |
Output is correct |
52 |
Correct |
335 ms |
59416 KB |
Output is correct |
53 |
Correct |
326 ms |
56716 KB |
Output is correct |
54 |
Correct |
284 ms |
44380 KB |
Output is correct |
55 |
Correct |
343 ms |
60364 KB |
Output is correct |
56 |
Correct |
344 ms |
59668 KB |
Output is correct |
57 |
Correct |
445 ms |
62284 KB |
Output is correct |
58 |
Correct |
360 ms |
60396 KB |
Output is correct |
59 |
Correct |
146 ms |
20192 KB |
Output is correct |
60 |
Correct |
336 ms |
58732 KB |
Output is correct |
61 |
Correct |
339 ms |
57196 KB |
Output is correct |
62 |
Correct |
357 ms |
60492 KB |
Output is correct |
63 |
Correct |
528 ms |
62704 KB |
Output is correct |
64 |
Correct |
8 ms |
9472 KB |
Output is correct |
65 |
Correct |
7 ms |
9472 KB |
Output is correct |
66 |
Correct |
8 ms |
9472 KB |
Output is correct |
67 |
Correct |
8 ms |
9600 KB |
Output is correct |
68 |
Correct |
7 ms |
9344 KB |
Output is correct |
69 |
Correct |
9 ms |
9728 KB |
Output is correct |
70 |
Correct |
8 ms |
9728 KB |
Output is correct |
71 |
Correct |
8 ms |
9728 KB |
Output is correct |
72 |
Correct |
7 ms |
9472 KB |
Output is correct |
73 |
Correct |
9 ms |
9728 KB |
Output is correct |
74 |
Runtime error |
484 ms |
524288 KB |
Execution killed with signal 9 |
75 |
Halted |
0 ms |
0 KB |
- |