#include "swap.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 200010;
const int inf = 2e9;
const int lg = 18;
int par[N];
int parw[N];
int sz[N];
int tim[N];
bool pleaf[N];
bool proot[N];
vector<int> A[N];
int root (int v) { return par[v] == -1? v: root(par[v]); }
void unite(int v, int u, int w)
{
int v0 = v, u0 = u;
v = root(v);
u = root(u);
if (v == u) {
proot[v] = false;
tim[v] = min(tim[v], w);
return;
}
if (sz[v] < sz[u]) {
swap(v, u);
swap(v0, u0);
}
par[u] = v;
parw[u] = w;
A[v].push_back(u);
sz[v] += sz[u];
if (!proot[v] || !proot[u] || !pleaf[v0] || !pleaf[u0]) {
proot[v] = false;
tim[v] = min(tim[v], w);
}
if (sz[v] - sz[u] != 1)
pleaf[v0] = false;
if (sz[u] != 1)
pleaf[u0] = false;
}
void init(int n, int m,
std::vector<int> u, std::vector<int> v, std::vector<int> w) {
vector<pair<int,pii>> vec;
Loop (i,0,m)
vec.push_back({w[i],{v[i],u[i]}});
fill(par, par+N, -1);
fill(sz, sz+N, 1);
fill(tim, tim+N, inf);
fill(proot, proot+N, true);
fill(pleaf, pleaf+N, true);
sort(vec.begin(), vec.end());
for (auto dard : vec)
unite(dard.second.first, dard.second.second, dard.first);
}
int height(int v)
{
int ans = 0;
while (par[v] != -1) {
++ans;
v = par[v];
}
return ans;
}
int getMinimumFuelCapacity(int x, int y) {
int diff = height(y) - height(x);
int w = 0;
while (diff > 0) {
w = max(w, parw[y]);
y = par[y];
--diff;
}
while (diff < 0) {
w = max(w, parw[x]);
x = par[x];
++diff;
}
while (x != y) {
w = max(w, parw[x]);
w = max(w, parw[y]);
x = par[x];
y = par[y];
}
int t = tim[x];
while (par[x] != -1) {
t = min(t, max(parw[x], tim[par[x]]));
x = par[x];
}
w = max(w, t);
return w == inf? -1: w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
3 ms |
7636 KB |
Output is correct |
4 |
Correct |
4 ms |
7764 KB |
Output is correct |
5 |
Correct |
5 ms |
7764 KB |
Output is correct |
6 |
Correct |
4 ms |
7764 KB |
Output is correct |
7 |
Correct |
5 ms |
7764 KB |
Output is correct |
8 |
Correct |
4 ms |
7704 KB |
Output is correct |
9 |
Correct |
42 ms |
12096 KB |
Output is correct |
10 |
Correct |
57 ms |
13156 KB |
Output is correct |
11 |
Correct |
50 ms |
12884 KB |
Output is correct |
12 |
Correct |
53 ms |
13148 KB |
Output is correct |
13 |
Correct |
45 ms |
12688 KB |
Output is correct |
14 |
Correct |
48 ms |
12180 KB |
Output is correct |
15 |
Correct |
116 ms |
14580 KB |
Output is correct |
16 |
Correct |
119 ms |
14420 KB |
Output is correct |
17 |
Correct |
115 ms |
14744 KB |
Output is correct |
18 |
Correct |
97 ms |
14072 KB |
Output is correct |
19 |
Correct |
61 ms |
12068 KB |
Output is correct |
20 |
Correct |
120 ms |
14824 KB |
Output is correct |
21 |
Correct |
112 ms |
15044 KB |
Output is correct |
22 |
Correct |
120 ms |
15196 KB |
Output is correct |
23 |
Correct |
97 ms |
14556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
90 ms |
14192 KB |
Output is correct |
4 |
Correct |
89 ms |
18016 KB |
Output is correct |
5 |
Correct |
93 ms |
18440 KB |
Output is correct |
6 |
Correct |
91 ms |
17944 KB |
Output is correct |
7 |
Correct |
92 ms |
18372 KB |
Output is correct |
8 |
Correct |
92 ms |
18072 KB |
Output is correct |
9 |
Correct |
96 ms |
18116 KB |
Output is correct |
10 |
Correct |
94 ms |
18100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
3 ms |
7636 KB |
Output is correct |
4 |
Correct |
4 ms |
7764 KB |
Output is correct |
5 |
Correct |
5 ms |
7764 KB |
Output is correct |
6 |
Correct |
4 ms |
7764 KB |
Output is correct |
7 |
Correct |
5 ms |
7764 KB |
Output is correct |
8 |
Correct |
4 ms |
7704 KB |
Output is correct |
9 |
Correct |
4 ms |
7636 KB |
Output is correct |
10 |
Correct |
5 ms |
7764 KB |
Output is correct |
11 |
Correct |
4 ms |
7712 KB |
Output is correct |
12 |
Correct |
5 ms |
7704 KB |
Output is correct |
13 |
Correct |
4 ms |
7764 KB |
Output is correct |
14 |
Correct |
5 ms |
7704 KB |
Output is correct |
15 |
Correct |
4 ms |
7764 KB |
Output is correct |
16 |
Correct |
4 ms |
7764 KB |
Output is correct |
17 |
Correct |
4 ms |
7708 KB |
Output is correct |
18 |
Correct |
4 ms |
7708 KB |
Output is correct |
19 |
Correct |
4 ms |
7764 KB |
Output is correct |
20 |
Correct |
5 ms |
7704 KB |
Output is correct |
21 |
Correct |
5 ms |
7764 KB |
Output is correct |
22 |
Correct |
5 ms |
7836 KB |
Output is correct |
23 |
Correct |
4 ms |
7764 KB |
Output is correct |
24 |
Correct |
4 ms |
7836 KB |
Output is correct |
25 |
Correct |
5 ms |
7836 KB |
Output is correct |
26 |
Correct |
5 ms |
7880 KB |
Output is correct |
27 |
Correct |
5 ms |
7764 KB |
Output is correct |
28 |
Correct |
4 ms |
7764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
4 ms |
7636 KB |
Output is correct |
4 |
Correct |
3 ms |
7636 KB |
Output is correct |
5 |
Correct |
4 ms |
7764 KB |
Output is correct |
6 |
Correct |
5 ms |
7764 KB |
Output is correct |
7 |
Correct |
4 ms |
7764 KB |
Output is correct |
8 |
Correct |
5 ms |
7764 KB |
Output is correct |
9 |
Correct |
4 ms |
7704 KB |
Output is correct |
10 |
Correct |
42 ms |
12096 KB |
Output is correct |
11 |
Correct |
57 ms |
13156 KB |
Output is correct |
12 |
Correct |
50 ms |
12884 KB |
Output is correct |
13 |
Correct |
53 ms |
13148 KB |
Output is correct |
14 |
Correct |
45 ms |
12688 KB |
Output is correct |
15 |
Correct |
5 ms |
7764 KB |
Output is correct |
16 |
Correct |
4 ms |
7712 KB |
Output is correct |
17 |
Correct |
5 ms |
7704 KB |
Output is correct |
18 |
Correct |
4 ms |
7764 KB |
Output is correct |
19 |
Correct |
5 ms |
7704 KB |
Output is correct |
20 |
Correct |
4 ms |
7764 KB |
Output is correct |
21 |
Correct |
4 ms |
7764 KB |
Output is correct |
22 |
Correct |
4 ms |
7708 KB |
Output is correct |
23 |
Correct |
4 ms |
7708 KB |
Output is correct |
24 |
Correct |
4 ms |
7764 KB |
Output is correct |
25 |
Correct |
5 ms |
7704 KB |
Output is correct |
26 |
Correct |
5 ms |
7764 KB |
Output is correct |
27 |
Correct |
5 ms |
7836 KB |
Output is correct |
28 |
Correct |
4 ms |
7764 KB |
Output is correct |
29 |
Correct |
4 ms |
7836 KB |
Output is correct |
30 |
Correct |
5 ms |
7836 KB |
Output is correct |
31 |
Correct |
5 ms |
7880 KB |
Output is correct |
32 |
Correct |
5 ms |
7764 KB |
Output is correct |
33 |
Correct |
4 ms |
7764 KB |
Output is correct |
34 |
Correct |
10 ms |
8688 KB |
Output is correct |
35 |
Correct |
52 ms |
14760 KB |
Output is correct |
36 |
Correct |
52 ms |
14740 KB |
Output is correct |
37 |
Correct |
52 ms |
14784 KB |
Output is correct |
38 |
Correct |
53 ms |
14664 KB |
Output is correct |
39 |
Correct |
51 ms |
14532 KB |
Output is correct |
40 |
Correct |
46 ms |
13980 KB |
Output is correct |
41 |
Correct |
54 ms |
15040 KB |
Output is correct |
42 |
Correct |
53 ms |
14716 KB |
Output is correct |
43 |
Correct |
45 ms |
14220 KB |
Output is correct |
44 |
Correct |
54 ms |
14864 KB |
Output is correct |
45 |
Correct |
71 ms |
17212 KB |
Output is correct |
46 |
Correct |
50 ms |
14784 KB |
Output is correct |
47 |
Correct |
53 ms |
14736 KB |
Output is correct |
48 |
Correct |
55 ms |
15244 KB |
Output is correct |
49 |
Correct |
64 ms |
16256 KB |
Output is correct |
50 |
Correct |
52 ms |
14400 KB |
Output is correct |
51 |
Correct |
62 ms |
15908 KB |
Output is correct |
52 |
Correct |
80 ms |
18512 KB |
Output is correct |
53 |
Correct |
86 ms |
19376 KB |
Output is correct |
54 |
Correct |
102 ms |
20412 KB |
Output is correct |
55 |
Correct |
52 ms |
14256 KB |
Output is correct |
56 |
Correct |
86 ms |
18844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
3 ms |
7636 KB |
Output is correct |
4 |
Correct |
4 ms |
7764 KB |
Output is correct |
5 |
Correct |
5 ms |
7764 KB |
Output is correct |
6 |
Correct |
4 ms |
7764 KB |
Output is correct |
7 |
Correct |
5 ms |
7764 KB |
Output is correct |
8 |
Correct |
4 ms |
7704 KB |
Output is correct |
9 |
Correct |
42 ms |
12096 KB |
Output is correct |
10 |
Correct |
57 ms |
13156 KB |
Output is correct |
11 |
Correct |
50 ms |
12884 KB |
Output is correct |
12 |
Correct |
53 ms |
13148 KB |
Output is correct |
13 |
Correct |
45 ms |
12688 KB |
Output is correct |
14 |
Correct |
48 ms |
12180 KB |
Output is correct |
15 |
Correct |
116 ms |
14580 KB |
Output is correct |
16 |
Correct |
119 ms |
14420 KB |
Output is correct |
17 |
Correct |
115 ms |
14744 KB |
Output is correct |
18 |
Correct |
97 ms |
14072 KB |
Output is correct |
19 |
Correct |
90 ms |
14192 KB |
Output is correct |
20 |
Correct |
89 ms |
18016 KB |
Output is correct |
21 |
Correct |
93 ms |
18440 KB |
Output is correct |
22 |
Correct |
91 ms |
17944 KB |
Output is correct |
23 |
Correct |
92 ms |
18372 KB |
Output is correct |
24 |
Correct |
92 ms |
18072 KB |
Output is correct |
25 |
Correct |
96 ms |
18116 KB |
Output is correct |
26 |
Correct |
94 ms |
18100 KB |
Output is correct |
27 |
Correct |
5 ms |
7764 KB |
Output is correct |
28 |
Correct |
4 ms |
7712 KB |
Output is correct |
29 |
Correct |
5 ms |
7704 KB |
Output is correct |
30 |
Correct |
4 ms |
7764 KB |
Output is correct |
31 |
Correct |
5 ms |
7704 KB |
Output is correct |
32 |
Correct |
4 ms |
7764 KB |
Output is correct |
33 |
Correct |
4 ms |
7764 KB |
Output is correct |
34 |
Correct |
4 ms |
7708 KB |
Output is correct |
35 |
Correct |
4 ms |
7708 KB |
Output is correct |
36 |
Correct |
10 ms |
8688 KB |
Output is correct |
37 |
Correct |
52 ms |
14760 KB |
Output is correct |
38 |
Correct |
52 ms |
14740 KB |
Output is correct |
39 |
Correct |
52 ms |
14784 KB |
Output is correct |
40 |
Correct |
53 ms |
14664 KB |
Output is correct |
41 |
Correct |
51 ms |
14532 KB |
Output is correct |
42 |
Correct |
46 ms |
13980 KB |
Output is correct |
43 |
Correct |
54 ms |
15040 KB |
Output is correct |
44 |
Correct |
53 ms |
14716 KB |
Output is correct |
45 |
Correct |
45 ms |
14220 KB |
Output is correct |
46 |
Correct |
54 ms |
14864 KB |
Output is correct |
47 |
Correct |
15 ms |
9012 KB |
Output is correct |
48 |
Correct |
116 ms |
18632 KB |
Output is correct |
49 |
Correct |
115 ms |
18624 KB |
Output is correct |
50 |
Correct |
113 ms |
18600 KB |
Output is correct |
51 |
Correct |
110 ms |
18552 KB |
Output is correct |
52 |
Correct |
111 ms |
18192 KB |
Output is correct |
53 |
Correct |
100 ms |
17652 KB |
Output is correct |
54 |
Correct |
122 ms |
19412 KB |
Output is correct |
55 |
Correct |
124 ms |
18624 KB |
Output is correct |
56 |
Correct |
102 ms |
18136 KB |
Output is correct |
57 |
Correct |
120 ms |
19148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7636 KB |
Output is correct |
2 |
Correct |
4 ms |
7636 KB |
Output is correct |
3 |
Correct |
4 ms |
7636 KB |
Output is correct |
4 |
Correct |
3 ms |
7636 KB |
Output is correct |
5 |
Correct |
4 ms |
7764 KB |
Output is correct |
6 |
Correct |
5 ms |
7764 KB |
Output is correct |
7 |
Correct |
4 ms |
7764 KB |
Output is correct |
8 |
Correct |
5 ms |
7764 KB |
Output is correct |
9 |
Correct |
4 ms |
7704 KB |
Output is correct |
10 |
Correct |
42 ms |
12096 KB |
Output is correct |
11 |
Correct |
57 ms |
13156 KB |
Output is correct |
12 |
Correct |
50 ms |
12884 KB |
Output is correct |
13 |
Correct |
53 ms |
13148 KB |
Output is correct |
14 |
Correct |
45 ms |
12688 KB |
Output is correct |
15 |
Correct |
48 ms |
12180 KB |
Output is correct |
16 |
Correct |
116 ms |
14580 KB |
Output is correct |
17 |
Correct |
119 ms |
14420 KB |
Output is correct |
18 |
Correct |
115 ms |
14744 KB |
Output is correct |
19 |
Correct |
97 ms |
14072 KB |
Output is correct |
20 |
Correct |
90 ms |
14192 KB |
Output is correct |
21 |
Correct |
89 ms |
18016 KB |
Output is correct |
22 |
Correct |
93 ms |
18440 KB |
Output is correct |
23 |
Correct |
91 ms |
17944 KB |
Output is correct |
24 |
Correct |
92 ms |
18372 KB |
Output is correct |
25 |
Correct |
92 ms |
18072 KB |
Output is correct |
26 |
Correct |
96 ms |
18116 KB |
Output is correct |
27 |
Correct |
94 ms |
18100 KB |
Output is correct |
28 |
Correct |
5 ms |
7764 KB |
Output is correct |
29 |
Correct |
4 ms |
7712 KB |
Output is correct |
30 |
Correct |
5 ms |
7704 KB |
Output is correct |
31 |
Correct |
4 ms |
7764 KB |
Output is correct |
32 |
Correct |
5 ms |
7704 KB |
Output is correct |
33 |
Correct |
4 ms |
7764 KB |
Output is correct |
34 |
Correct |
4 ms |
7764 KB |
Output is correct |
35 |
Correct |
4 ms |
7708 KB |
Output is correct |
36 |
Correct |
4 ms |
7708 KB |
Output is correct |
37 |
Correct |
10 ms |
8688 KB |
Output is correct |
38 |
Correct |
52 ms |
14760 KB |
Output is correct |
39 |
Correct |
52 ms |
14740 KB |
Output is correct |
40 |
Correct |
52 ms |
14784 KB |
Output is correct |
41 |
Correct |
53 ms |
14664 KB |
Output is correct |
42 |
Correct |
51 ms |
14532 KB |
Output is correct |
43 |
Correct |
46 ms |
13980 KB |
Output is correct |
44 |
Correct |
54 ms |
15040 KB |
Output is correct |
45 |
Correct |
53 ms |
14716 KB |
Output is correct |
46 |
Correct |
45 ms |
14220 KB |
Output is correct |
47 |
Correct |
54 ms |
14864 KB |
Output is correct |
48 |
Correct |
15 ms |
9012 KB |
Output is correct |
49 |
Correct |
116 ms |
18632 KB |
Output is correct |
50 |
Correct |
115 ms |
18624 KB |
Output is correct |
51 |
Correct |
113 ms |
18600 KB |
Output is correct |
52 |
Correct |
110 ms |
18552 KB |
Output is correct |
53 |
Correct |
111 ms |
18192 KB |
Output is correct |
54 |
Correct |
100 ms |
17652 KB |
Output is correct |
55 |
Correct |
122 ms |
19412 KB |
Output is correct |
56 |
Correct |
124 ms |
18624 KB |
Output is correct |
57 |
Correct |
102 ms |
18136 KB |
Output is correct |
58 |
Correct |
120 ms |
19148 KB |
Output is correct |
59 |
Correct |
61 ms |
12068 KB |
Output is correct |
60 |
Correct |
120 ms |
14824 KB |
Output is correct |
61 |
Correct |
112 ms |
15044 KB |
Output is correct |
62 |
Correct |
120 ms |
15196 KB |
Output is correct |
63 |
Correct |
97 ms |
14556 KB |
Output is correct |
64 |
Correct |
4 ms |
7764 KB |
Output is correct |
65 |
Correct |
5 ms |
7704 KB |
Output is correct |
66 |
Correct |
5 ms |
7764 KB |
Output is correct |
67 |
Correct |
5 ms |
7836 KB |
Output is correct |
68 |
Correct |
4 ms |
7764 KB |
Output is correct |
69 |
Correct |
4 ms |
7836 KB |
Output is correct |
70 |
Correct |
5 ms |
7836 KB |
Output is correct |
71 |
Correct |
5 ms |
7880 KB |
Output is correct |
72 |
Correct |
5 ms |
7764 KB |
Output is correct |
73 |
Correct |
4 ms |
7764 KB |
Output is correct |
74 |
Correct |
71 ms |
17212 KB |
Output is correct |
75 |
Correct |
50 ms |
14784 KB |
Output is correct |
76 |
Correct |
53 ms |
14736 KB |
Output is correct |
77 |
Correct |
55 ms |
15244 KB |
Output is correct |
78 |
Correct |
64 ms |
16256 KB |
Output is correct |
79 |
Correct |
52 ms |
14400 KB |
Output is correct |
80 |
Correct |
62 ms |
15908 KB |
Output is correct |
81 |
Correct |
80 ms |
18512 KB |
Output is correct |
82 |
Correct |
86 ms |
19376 KB |
Output is correct |
83 |
Correct |
102 ms |
20412 KB |
Output is correct |
84 |
Correct |
52 ms |
14256 KB |
Output is correct |
85 |
Correct |
86 ms |
18844 KB |
Output is correct |
86 |
Correct |
42 ms |
11884 KB |
Output is correct |
87 |
Correct |
115 ms |
18608 KB |
Output is correct |
88 |
Correct |
112 ms |
18624 KB |
Output is correct |
89 |
Correct |
107 ms |
18648 KB |
Output is correct |
90 |
Correct |
127 ms |
19988 KB |
Output is correct |
91 |
Correct |
125 ms |
19528 KB |
Output is correct |
92 |
Correct |
128 ms |
19380 KB |
Output is correct |
93 |
Correct |
141 ms |
22188 KB |
Output is correct |
94 |
Correct |
150 ms |
23180 KB |
Output is correct |
95 |
Correct |
176 ms |
24348 KB |
Output is correct |
96 |
Correct |
101 ms |
18152 KB |
Output is correct |
97 |
Correct |
129 ms |
20756 KB |
Output is correct |