#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][23];
int can[300200][23];
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 < 23; 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 < 300200; 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 = 22; i >= 0; i-- ){
if( !upper( up[x][i] , y ) ){
x = up[x][i];
}
}
return up[x][0];
}
int get1( int x )
{
for( int i = 22; 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 )];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9984 KB |
Output is correct |
5 |
Correct |
8 ms |
10240 KB |
Output is correct |
6 |
Correct |
8 ms |
10112 KB |
Output is correct |
7 |
Correct |
8 ms |
10240 KB |
Output is correct |
8 |
Correct |
8 ms |
10240 KB |
Output is correct |
9 |
Correct |
141 ms |
45424 KB |
Output is correct |
10 |
Correct |
178 ms |
53364 KB |
Output is correct |
11 |
Correct |
179 ms |
52848 KB |
Output is correct |
12 |
Correct |
184 ms |
55152 KB |
Output is correct |
13 |
Correct |
210 ms |
57456 KB |
Output is correct |
14 |
Correct |
154 ms |
45552 KB |
Output is correct |
15 |
Correct |
247 ms |
55408 KB |
Output is correct |
16 |
Correct |
246 ms |
53996 KB |
Output is correct |
17 |
Correct |
262 ms |
56816 KB |
Output is correct |
18 |
Correct |
276 ms |
59120 KB |
Output is correct |
19 |
Correct |
131 ms |
20472 KB |
Output is correct |
20 |
Correct |
319 ms |
56428 KB |
Output is correct |
21 |
Correct |
327 ms |
54972 KB |
Output is correct |
22 |
Correct |
340 ms |
58060 KB |
Output is correct |
23 |
Correct |
503 ms |
60492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
398 ms |
59904 KB |
Output is correct |
4 |
Correct |
401 ms |
62284 KB |
Output is correct |
5 |
Correct |
408 ms |
60712 KB |
Output is correct |
6 |
Correct |
404 ms |
61944 KB |
Output is correct |
7 |
Correct |
419 ms |
61420 KB |
Output is correct |
8 |
Correct |
404 ms |
59372 KB |
Output is correct |
9 |
Correct |
406 ms |
61144 KB |
Output is correct |
10 |
Correct |
407 ms |
58940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9728 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
8 ms |
10240 KB |
Output is correct |
7 |
Correct |
8 ms |
10112 KB |
Output is correct |
8 |
Correct |
8 ms |
10240 KB |
Output is correct |
9 |
Correct |
8 ms |
10240 KB |
Output is correct |
10 |
Correct |
8 ms |
10240 KB |
Output is correct |
11 |
Correct |
8 ms |
10240 KB |
Output is correct |
12 |
Correct |
8 ms |
10240 KB |
Output is correct |
13 |
Correct |
8 ms |
10112 KB |
Output is correct |
14 |
Correct |
8 ms |
10112 KB |
Output is correct |
15 |
Correct |
8 ms |
10240 KB |
Output is correct |
16 |
Correct |
8 ms |
10240 KB |
Output is correct |
17 |
Correct |
8 ms |
10240 KB |
Output is correct |
18 |
Correct |
8 ms |
10240 KB |
Output is correct |
19 |
Correct |
8 ms |
10112 KB |
Output is correct |
20 |
Correct |
8 ms |
10240 KB |
Output is correct |
21 |
Correct |
8 ms |
10240 KB |
Output is correct |
22 |
Correct |
8 ms |
10368 KB |
Output is correct |
23 |
Correct |
8 ms |
10112 KB |
Output is correct |
24 |
Correct |
9 ms |
10624 KB |
Output is correct |
25 |
Correct |
11 ms |
10496 KB |
Output is correct |
26 |
Correct |
9 ms |
10496 KB |
Output is correct |
27 |
Correct |
8 ms |
10240 KB |
Output is correct |
28 |
Correct |
9 ms |
10496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9728 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
8 ms |
10240 KB |
Output is correct |
7 |
Correct |
8 ms |
10112 KB |
Output is correct |
8 |
Correct |
8 ms |
10240 KB |
Output is correct |
9 |
Correct |
8 ms |
10240 KB |
Output is correct |
10 |
Correct |
141 ms |
45424 KB |
Output is correct |
11 |
Correct |
178 ms |
53364 KB |
Output is correct |
12 |
Correct |
179 ms |
52848 KB |
Output is correct |
13 |
Correct |
184 ms |
55152 KB |
Output is correct |
14 |
Correct |
210 ms |
57456 KB |
Output is correct |
15 |
Correct |
8 ms |
10240 KB |
Output is correct |
16 |
Correct |
8 ms |
10240 KB |
Output is correct |
17 |
Correct |
8 ms |
10240 KB |
Output is correct |
18 |
Correct |
8 ms |
10112 KB |
Output is correct |
19 |
Correct |
8 ms |
10112 KB |
Output is correct |
20 |
Correct |
8 ms |
10240 KB |
Output is correct |
21 |
Correct |
8 ms |
10240 KB |
Output is correct |
22 |
Correct |
8 ms |
10240 KB |
Output is correct |
23 |
Correct |
8 ms |
10240 KB |
Output is correct |
24 |
Correct |
28 ms |
16000 KB |
Output is correct |
25 |
Correct |
180 ms |
55152 KB |
Output is correct |
26 |
Correct |
182 ms |
55152 KB |
Output is correct |
27 |
Correct |
178 ms |
55152 KB |
Output is correct |
28 |
Correct |
178 ms |
54512 KB |
Output is correct |
29 |
Correct |
182 ms |
54256 KB |
Output is correct |
30 |
Correct |
161 ms |
50596 KB |
Output is correct |
31 |
Correct |
181 ms |
55152 KB |
Output is correct |
32 |
Correct |
184 ms |
55152 KB |
Output is correct |
33 |
Correct |
200 ms |
58300 KB |
Output is correct |
34 |
Correct |
190 ms |
55152 KB |
Output is correct |
35 |
Correct |
8 ms |
10112 KB |
Output is correct |
36 |
Correct |
8 ms |
10240 KB |
Output is correct |
37 |
Correct |
8 ms |
10240 KB |
Output is correct |
38 |
Correct |
8 ms |
10368 KB |
Output is correct |
39 |
Correct |
8 ms |
10112 KB |
Output is correct |
40 |
Correct |
9 ms |
10624 KB |
Output is correct |
41 |
Correct |
11 ms |
10496 KB |
Output is correct |
42 |
Correct |
9 ms |
10496 KB |
Output is correct |
43 |
Correct |
8 ms |
10240 KB |
Output is correct |
44 |
Correct |
9 ms |
10496 KB |
Output is correct |
45 |
Correct |
261 ms |
67504 KB |
Output is correct |
46 |
Correct |
179 ms |
55152 KB |
Output is correct |
47 |
Correct |
184 ms |
55152 KB |
Output is correct |
48 |
Correct |
224 ms |
59248 KB |
Output is correct |
49 |
Correct |
172 ms |
58092 KB |
Output is correct |
50 |
Correct |
139 ms |
47856 KB |
Output is correct |
51 |
Correct |
215 ms |
59376 KB |
Output is correct |
52 |
Correct |
269 ms |
73964 KB |
Output is correct |
53 |
Correct |
324 ms |
78188 KB |
Output is correct |
54 |
Correct |
321 ms |
85740 KB |
Output is correct |
55 |
Correct |
209 ms |
58000 KB |
Output is correct |
56 |
Correct |
316 ms |
78444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9984 KB |
Output is correct |
5 |
Correct |
8 ms |
10240 KB |
Output is correct |
6 |
Correct |
8 ms |
10112 KB |
Output is correct |
7 |
Correct |
8 ms |
10240 KB |
Output is correct |
8 |
Correct |
8 ms |
10240 KB |
Output is correct |
9 |
Correct |
141 ms |
45424 KB |
Output is correct |
10 |
Correct |
178 ms |
53364 KB |
Output is correct |
11 |
Correct |
179 ms |
52848 KB |
Output is correct |
12 |
Correct |
184 ms |
55152 KB |
Output is correct |
13 |
Correct |
210 ms |
57456 KB |
Output is correct |
14 |
Correct |
154 ms |
45552 KB |
Output is correct |
15 |
Correct |
247 ms |
55408 KB |
Output is correct |
16 |
Correct |
246 ms |
53996 KB |
Output is correct |
17 |
Correct |
262 ms |
56816 KB |
Output is correct |
18 |
Correct |
276 ms |
59120 KB |
Output is correct |
19 |
Correct |
398 ms |
59904 KB |
Output is correct |
20 |
Correct |
401 ms |
62284 KB |
Output is correct |
21 |
Correct |
408 ms |
60712 KB |
Output is correct |
22 |
Correct |
404 ms |
61944 KB |
Output is correct |
23 |
Correct |
419 ms |
61420 KB |
Output is correct |
24 |
Correct |
404 ms |
59372 KB |
Output is correct |
25 |
Correct |
406 ms |
61144 KB |
Output is correct |
26 |
Correct |
407 ms |
58940 KB |
Output is correct |
27 |
Correct |
8 ms |
10240 KB |
Output is correct |
28 |
Correct |
8 ms |
10240 KB |
Output is correct |
29 |
Correct |
8 ms |
10240 KB |
Output is correct |
30 |
Correct |
8 ms |
10112 KB |
Output is correct |
31 |
Correct |
8 ms |
10112 KB |
Output is correct |
32 |
Correct |
8 ms |
10240 KB |
Output is correct |
33 |
Correct |
8 ms |
10240 KB |
Output is correct |
34 |
Correct |
8 ms |
10240 KB |
Output is correct |
35 |
Correct |
8 ms |
10240 KB |
Output is correct |
36 |
Correct |
28 ms |
16000 KB |
Output is correct |
37 |
Correct |
180 ms |
55152 KB |
Output is correct |
38 |
Correct |
182 ms |
55152 KB |
Output is correct |
39 |
Correct |
178 ms |
55152 KB |
Output is correct |
40 |
Correct |
178 ms |
54512 KB |
Output is correct |
41 |
Correct |
182 ms |
54256 KB |
Output is correct |
42 |
Correct |
161 ms |
50596 KB |
Output is correct |
43 |
Correct |
181 ms |
55152 KB |
Output is correct |
44 |
Correct |
184 ms |
55152 KB |
Output is correct |
45 |
Correct |
200 ms |
58300 KB |
Output is correct |
46 |
Correct |
190 ms |
55152 KB |
Output is correct |
47 |
Correct |
36 ms |
15736 KB |
Output is correct |
48 |
Correct |
322 ms |
57548 KB |
Output is correct |
49 |
Correct |
311 ms |
57548 KB |
Output is correct |
50 |
Correct |
345 ms |
57296 KB |
Output is correct |
51 |
Correct |
318 ms |
57064 KB |
Output is correct |
52 |
Correct |
317 ms |
54448 KB |
Output is correct |
53 |
Correct |
267 ms |
43104 KB |
Output is correct |
54 |
Correct |
326 ms |
58060 KB |
Output is correct |
55 |
Correct |
338 ms |
57420 KB |
Output is correct |
56 |
Correct |
417 ms |
59924 KB |
Output is correct |
57 |
Correct |
340 ms |
58060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9728 KB |
Output is correct |
2 |
Correct |
7 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9728 KB |
Output is correct |
4 |
Correct |
7 ms |
9728 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
8 ms |
10240 KB |
Output is correct |
7 |
Correct |
8 ms |
10112 KB |
Output is correct |
8 |
Correct |
8 ms |
10240 KB |
Output is correct |
9 |
Correct |
8 ms |
10240 KB |
Output is correct |
10 |
Correct |
141 ms |
45424 KB |
Output is correct |
11 |
Correct |
178 ms |
53364 KB |
Output is correct |
12 |
Correct |
179 ms |
52848 KB |
Output is correct |
13 |
Correct |
184 ms |
55152 KB |
Output is correct |
14 |
Correct |
210 ms |
57456 KB |
Output is correct |
15 |
Correct |
154 ms |
45552 KB |
Output is correct |
16 |
Correct |
247 ms |
55408 KB |
Output is correct |
17 |
Correct |
246 ms |
53996 KB |
Output is correct |
18 |
Correct |
262 ms |
56816 KB |
Output is correct |
19 |
Correct |
276 ms |
59120 KB |
Output is correct |
20 |
Correct |
398 ms |
59904 KB |
Output is correct |
21 |
Correct |
401 ms |
62284 KB |
Output is correct |
22 |
Correct |
408 ms |
60712 KB |
Output is correct |
23 |
Correct |
404 ms |
61944 KB |
Output is correct |
24 |
Correct |
419 ms |
61420 KB |
Output is correct |
25 |
Correct |
404 ms |
59372 KB |
Output is correct |
26 |
Correct |
406 ms |
61144 KB |
Output is correct |
27 |
Correct |
407 ms |
58940 KB |
Output is correct |
28 |
Correct |
8 ms |
10240 KB |
Output is correct |
29 |
Correct |
8 ms |
10240 KB |
Output is correct |
30 |
Correct |
8 ms |
10240 KB |
Output is correct |
31 |
Correct |
8 ms |
10112 KB |
Output is correct |
32 |
Correct |
8 ms |
10112 KB |
Output is correct |
33 |
Correct |
8 ms |
10240 KB |
Output is correct |
34 |
Correct |
8 ms |
10240 KB |
Output is correct |
35 |
Correct |
8 ms |
10240 KB |
Output is correct |
36 |
Correct |
8 ms |
10240 KB |
Output is correct |
37 |
Correct |
28 ms |
16000 KB |
Output is correct |
38 |
Correct |
180 ms |
55152 KB |
Output is correct |
39 |
Correct |
182 ms |
55152 KB |
Output is correct |
40 |
Correct |
178 ms |
55152 KB |
Output is correct |
41 |
Correct |
178 ms |
54512 KB |
Output is correct |
42 |
Correct |
182 ms |
54256 KB |
Output is correct |
43 |
Correct |
161 ms |
50596 KB |
Output is correct |
44 |
Correct |
181 ms |
55152 KB |
Output is correct |
45 |
Correct |
184 ms |
55152 KB |
Output is correct |
46 |
Correct |
200 ms |
58300 KB |
Output is correct |
47 |
Correct |
190 ms |
55152 KB |
Output is correct |
48 |
Correct |
36 ms |
15736 KB |
Output is correct |
49 |
Correct |
322 ms |
57548 KB |
Output is correct |
50 |
Correct |
311 ms |
57548 KB |
Output is correct |
51 |
Correct |
345 ms |
57296 KB |
Output is correct |
52 |
Correct |
318 ms |
57064 KB |
Output is correct |
53 |
Correct |
317 ms |
54448 KB |
Output is correct |
54 |
Correct |
267 ms |
43104 KB |
Output is correct |
55 |
Correct |
326 ms |
58060 KB |
Output is correct |
56 |
Correct |
338 ms |
57420 KB |
Output is correct |
57 |
Correct |
417 ms |
59924 KB |
Output is correct |
58 |
Correct |
340 ms |
58060 KB |
Output is correct |
59 |
Correct |
131 ms |
20472 KB |
Output is correct |
60 |
Correct |
319 ms |
56428 KB |
Output is correct |
61 |
Correct |
327 ms |
54972 KB |
Output is correct |
62 |
Correct |
340 ms |
58060 KB |
Output is correct |
63 |
Correct |
503 ms |
60492 KB |
Output is correct |
64 |
Correct |
8 ms |
10112 KB |
Output is correct |
65 |
Correct |
8 ms |
10240 KB |
Output is correct |
66 |
Correct |
8 ms |
10240 KB |
Output is correct |
67 |
Correct |
8 ms |
10368 KB |
Output is correct |
68 |
Correct |
8 ms |
10112 KB |
Output is correct |
69 |
Correct |
9 ms |
10624 KB |
Output is correct |
70 |
Correct |
11 ms |
10496 KB |
Output is correct |
71 |
Correct |
9 ms |
10496 KB |
Output is correct |
72 |
Correct |
8 ms |
10240 KB |
Output is correct |
73 |
Correct |
9 ms |
10496 KB |
Output is correct |
74 |
Correct |
261 ms |
67504 KB |
Output is correct |
75 |
Correct |
179 ms |
55152 KB |
Output is correct |
76 |
Correct |
184 ms |
55152 KB |
Output is correct |
77 |
Correct |
224 ms |
59248 KB |
Output is correct |
78 |
Correct |
172 ms |
58092 KB |
Output is correct |
79 |
Correct |
139 ms |
47856 KB |
Output is correct |
80 |
Correct |
215 ms |
59376 KB |
Output is correct |
81 |
Correct |
269 ms |
73964 KB |
Output is correct |
82 |
Correct |
324 ms |
78188 KB |
Output is correct |
83 |
Correct |
321 ms |
85740 KB |
Output is correct |
84 |
Correct |
209 ms |
58000 KB |
Output is correct |
85 |
Correct |
316 ms |
78444 KB |
Output is correct |
86 |
Correct |
131 ms |
30452 KB |
Output is correct |
87 |
Correct |
326 ms |
57424 KB |
Output is correct |
88 |
Correct |
320 ms |
57548 KB |
Output is correct |
89 |
Correct |
430 ms |
59116 KB |
Output is correct |
90 |
Correct |
325 ms |
62700 KB |
Output is correct |
91 |
Correct |
337 ms |
58820 KB |
Output is correct |
92 |
Correct |
452 ms |
60012 KB |
Output is correct |
93 |
Correct |
433 ms |
74932 KB |
Output is correct |
94 |
Correct |
552 ms |
79636 KB |
Output is correct |
95 |
Correct |
468 ms |
87404 KB |
Output is correct |
96 |
Correct |
443 ms |
60112 KB |
Output is correct |
97 |
Correct |
503 ms |
69488 KB |
Output is correct |