#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define arr3 array<int, 3>
const int inf = 3e5;
const int infv = numeric_limits<int> :: max();
struct dsu{
vector<int> p, d, A;
vector<vector<int>> g;
vector<bool> f;
int n, cc, k;
void init(int ns){
n = ns;
d.resize(n + 1);
p.resize(inf + 1);
f.resize(inf + 1);
for (int i = 1; i <= inf; i++){
p[i] = i;
}
cc = n;
g.resize(inf + 1);
A.assign(inf + 1, infv);
}
int get(int v){
if (p[v] != v){
p[v] = get(p[v]);
}
return p[v];
}
void unite(int x, int y, int w){
int a = get(x), b = get(y);
if (a == b){
if (!f[a]){
cc++;
p[a] = cc;
A[cc] = w;
g[cc].pb(a);
f[cc] = 1;
}
return;
}
if (f[a] || f[b] || d[x] == 2 || d[y] == 2){
cc++;
p[a] = p[b] = cc;
A[cc] = w;
g[cc].pb(a);
g[cc].pb(b);
f[cc] = 1;
}
else {
cc++;
p[a] = p[b] = cc;
g[cc].pb(a);
g[cc].pb(b);
d[x]++; d[y]++;
}
}
vector<int> tin, tout, out;
vector<vector<int>> pw;
int lg, timer;
void fill(int v, int pr){
tin[v] = ++timer;
out[v] = min(out[pr], A[v]);
pw[v][0] = pr;
for (int i = 1; i <= lg; i++){
pw[v][i] = pw[pw[v][i - 1]][i - 1];
}
for (int i: g[v]){
fill(i, v);
}
tout[v] = timer;
}
void build(){
tin.resize(cc + 1);
tout.resize(cc + 1);
lg = log2(cc);
pw.resize(cc + 1);
for (int i = 1; i <= cc; i++){
pw[i].resize(lg + 1);
}
timer = 0;
out.assign(inf + 1, infv);
fill(cc, cc);
for (int i = 1; i <= inf; i++){
if (out[i] == infv){
out[i] = -1;
}
}
}
bool check(int x, int y){
return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}
int lca(int x, int y){
for (int i = lg; i >= 0; i--){
if (!check(pw[x][i], y)){
x = pw[x][i];
}
}
return pw[x][0];
}
int get(int x, int y){
return out[lca(x, y)];
}
};
dsu T;
int n, m;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W){
n = N; m = M;
vector<arr3> ed;
for (int i = 0; i < m; i++){
ed.pb({W[i], U[i] + 1, V[i] + 1});
}
sort(ed.begin(), ed.end());
T.init(n);
for (auto [f, x, y]: ed){
T.unite(x, y, f);
}
T.build();
}
int getMinimumFuelCapacity(int x, int y){
x++; y++;
return T.get(x, y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
5 ms |
11000 KB |
Output is correct |
4 |
Correct |
5 ms |
10920 KB |
Output is correct |
5 |
Correct |
6 ms |
11088 KB |
Output is correct |
6 |
Correct |
5 ms |
11088 KB |
Output is correct |
7 |
Correct |
7 ms |
11088 KB |
Output is correct |
8 |
Correct |
6 ms |
11088 KB |
Output is correct |
9 |
Correct |
88 ms |
33724 KB |
Output is correct |
10 |
Correct |
98 ms |
38788 KB |
Output is correct |
11 |
Correct |
98 ms |
38332 KB |
Output is correct |
12 |
Correct |
107 ms |
39868 KB |
Output is correct |
13 |
Correct |
111 ms |
41916 KB |
Output is correct |
14 |
Correct |
76 ms |
33800 KB |
Output is correct |
15 |
Correct |
150 ms |
40380 KB |
Output is correct |
16 |
Correct |
145 ms |
39612 KB |
Output is correct |
17 |
Correct |
153 ms |
41404 KB |
Output is correct |
18 |
Correct |
174 ms |
43452 KB |
Output is correct |
19 |
Correct |
61 ms |
18776 KB |
Output is correct |
20 |
Correct |
159 ms |
40844 KB |
Output is correct |
21 |
Correct |
156 ms |
40188 KB |
Output is correct |
22 |
Correct |
161 ms |
41904 KB |
Output is correct |
23 |
Correct |
205 ms |
43920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
183 ms |
43784 KB |
Output is correct |
4 |
Correct |
171 ms |
45456 KB |
Output is correct |
5 |
Correct |
177 ms |
44524 KB |
Output is correct |
6 |
Correct |
172 ms |
45096 KB |
Output is correct |
7 |
Correct |
193 ms |
44992 KB |
Output is correct |
8 |
Correct |
159 ms |
43552 KB |
Output is correct |
9 |
Correct |
167 ms |
44736 KB |
Output is correct |
10 |
Correct |
164 ms |
43316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
5 ms |
11000 KB |
Output is correct |
4 |
Correct |
5 ms |
10920 KB |
Output is correct |
5 |
Correct |
6 ms |
11088 KB |
Output is correct |
6 |
Correct |
5 ms |
11088 KB |
Output is correct |
7 |
Correct |
7 ms |
11088 KB |
Output is correct |
8 |
Correct |
6 ms |
11088 KB |
Output is correct |
9 |
Correct |
5 ms |
10832 KB |
Output is correct |
10 |
Correct |
5 ms |
11088 KB |
Output is correct |
11 |
Correct |
5 ms |
11088 KB |
Output is correct |
12 |
Correct |
5 ms |
11100 KB |
Output is correct |
13 |
Correct |
5 ms |
11088 KB |
Output is correct |
14 |
Correct |
5 ms |
11088 KB |
Output is correct |
15 |
Correct |
5 ms |
11088 KB |
Output is correct |
16 |
Correct |
5 ms |
11088 KB |
Output is correct |
17 |
Correct |
5 ms |
11088 KB |
Output is correct |
18 |
Correct |
5 ms |
11088 KB |
Output is correct |
19 |
Correct |
5 ms |
11088 KB |
Output is correct |
20 |
Correct |
6 ms |
11088 KB |
Output is correct |
21 |
Correct |
5 ms |
11088 KB |
Output is correct |
22 |
Correct |
5 ms |
11088 KB |
Output is correct |
23 |
Correct |
5 ms |
11088 KB |
Output is correct |
24 |
Correct |
5 ms |
11088 KB |
Output is correct |
25 |
Correct |
5 ms |
11344 KB |
Output is correct |
26 |
Correct |
6 ms |
11088 KB |
Output is correct |
27 |
Correct |
5 ms |
11088 KB |
Output is correct |
28 |
Correct |
6 ms |
11088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
5 ms |
10832 KB |
Output is correct |
4 |
Correct |
5 ms |
11000 KB |
Output is correct |
5 |
Correct |
5 ms |
10920 KB |
Output is correct |
6 |
Correct |
6 ms |
11088 KB |
Output is correct |
7 |
Correct |
5 ms |
11088 KB |
Output is correct |
8 |
Correct |
7 ms |
11088 KB |
Output is correct |
9 |
Correct |
6 ms |
11088 KB |
Output is correct |
10 |
Correct |
88 ms |
33724 KB |
Output is correct |
11 |
Correct |
98 ms |
38788 KB |
Output is correct |
12 |
Correct |
98 ms |
38332 KB |
Output is correct |
13 |
Correct |
107 ms |
39868 KB |
Output is correct |
14 |
Correct |
111 ms |
41916 KB |
Output is correct |
15 |
Correct |
5 ms |
11088 KB |
Output is correct |
16 |
Correct |
5 ms |
11088 KB |
Output is correct |
17 |
Correct |
5 ms |
11100 KB |
Output is correct |
18 |
Correct |
5 ms |
11088 KB |
Output is correct |
19 |
Correct |
5 ms |
11088 KB |
Output is correct |
20 |
Correct |
5 ms |
11088 KB |
Output is correct |
21 |
Correct |
5 ms |
11088 KB |
Output is correct |
22 |
Correct |
5 ms |
11088 KB |
Output is correct |
23 |
Correct |
5 ms |
11088 KB |
Output is correct |
24 |
Correct |
5 ms |
11088 KB |
Output is correct |
25 |
Correct |
6 ms |
11088 KB |
Output is correct |
26 |
Correct |
5 ms |
11088 KB |
Output is correct |
27 |
Correct |
5 ms |
11088 KB |
Output is correct |
28 |
Correct |
5 ms |
11088 KB |
Output is correct |
29 |
Correct |
5 ms |
11088 KB |
Output is correct |
30 |
Correct |
5 ms |
11344 KB |
Output is correct |
31 |
Correct |
6 ms |
11088 KB |
Output is correct |
32 |
Correct |
5 ms |
11088 KB |
Output is correct |
33 |
Correct |
6 ms |
11088 KB |
Output is correct |
34 |
Correct |
14 ms |
15288 KB |
Output is correct |
35 |
Correct |
95 ms |
41660 KB |
Output is correct |
36 |
Correct |
101 ms |
41660 KB |
Output is correct |
37 |
Correct |
102 ms |
41664 KB |
Output is correct |
38 |
Correct |
99 ms |
41172 KB |
Output is correct |
39 |
Correct |
92 ms |
40976 KB |
Output is correct |
40 |
Correct |
86 ms |
38640 KB |
Output is correct |
41 |
Correct |
108 ms |
41916 KB |
Output is correct |
42 |
Correct |
97 ms |
41700 KB |
Output is correct |
43 |
Correct |
96 ms |
44220 KB |
Output is correct |
44 |
Correct |
99 ms |
41916 KB |
Output is correct |
45 |
Correct |
104 ms |
40372 KB |
Output is correct |
46 |
Correct |
96 ms |
41668 KB |
Output is correct |
47 |
Correct |
97 ms |
41660 KB |
Output is correct |
48 |
Correct |
110 ms |
42428 KB |
Output is correct |
49 |
Correct |
51 ms |
19664 KB |
Output is correct |
50 |
Correct |
44 ms |
19228 KB |
Output is correct |
51 |
Correct |
82 ms |
35004 KB |
Output is correct |
52 |
Correct |
120 ms |
45552 KB |
Output is correct |
53 |
Correct |
163 ms |
51784 KB |
Output is correct |
54 |
Correct |
129 ms |
47416 KB |
Output is correct |
55 |
Correct |
104 ms |
44032 KB |
Output is correct |
56 |
Correct |
143 ms |
47296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
5 ms |
11000 KB |
Output is correct |
4 |
Correct |
5 ms |
10920 KB |
Output is correct |
5 |
Correct |
6 ms |
11088 KB |
Output is correct |
6 |
Correct |
5 ms |
11088 KB |
Output is correct |
7 |
Correct |
7 ms |
11088 KB |
Output is correct |
8 |
Correct |
6 ms |
11088 KB |
Output is correct |
9 |
Correct |
88 ms |
33724 KB |
Output is correct |
10 |
Correct |
98 ms |
38788 KB |
Output is correct |
11 |
Correct |
98 ms |
38332 KB |
Output is correct |
12 |
Correct |
107 ms |
39868 KB |
Output is correct |
13 |
Correct |
111 ms |
41916 KB |
Output is correct |
14 |
Correct |
76 ms |
33800 KB |
Output is correct |
15 |
Correct |
150 ms |
40380 KB |
Output is correct |
16 |
Correct |
145 ms |
39612 KB |
Output is correct |
17 |
Correct |
153 ms |
41404 KB |
Output is correct |
18 |
Correct |
174 ms |
43452 KB |
Output is correct |
19 |
Correct |
183 ms |
43784 KB |
Output is correct |
20 |
Correct |
171 ms |
45456 KB |
Output is correct |
21 |
Correct |
177 ms |
44524 KB |
Output is correct |
22 |
Correct |
172 ms |
45096 KB |
Output is correct |
23 |
Correct |
193 ms |
44992 KB |
Output is correct |
24 |
Correct |
159 ms |
43552 KB |
Output is correct |
25 |
Correct |
167 ms |
44736 KB |
Output is correct |
26 |
Correct |
164 ms |
43316 KB |
Output is correct |
27 |
Correct |
5 ms |
11088 KB |
Output is correct |
28 |
Correct |
5 ms |
11088 KB |
Output is correct |
29 |
Correct |
5 ms |
11100 KB |
Output is correct |
30 |
Correct |
5 ms |
11088 KB |
Output is correct |
31 |
Correct |
5 ms |
11088 KB |
Output is correct |
32 |
Correct |
5 ms |
11088 KB |
Output is correct |
33 |
Correct |
5 ms |
11088 KB |
Output is correct |
34 |
Correct |
5 ms |
11088 KB |
Output is correct |
35 |
Correct |
5 ms |
11088 KB |
Output is correct |
36 |
Correct |
14 ms |
15288 KB |
Output is correct |
37 |
Correct |
95 ms |
41660 KB |
Output is correct |
38 |
Correct |
101 ms |
41660 KB |
Output is correct |
39 |
Correct |
102 ms |
41664 KB |
Output is correct |
40 |
Correct |
99 ms |
41172 KB |
Output is correct |
41 |
Correct |
92 ms |
40976 KB |
Output is correct |
42 |
Correct |
86 ms |
38640 KB |
Output is correct |
43 |
Correct |
108 ms |
41916 KB |
Output is correct |
44 |
Correct |
97 ms |
41700 KB |
Output is correct |
45 |
Correct |
96 ms |
44220 KB |
Output is correct |
46 |
Correct |
99 ms |
41916 KB |
Output is correct |
47 |
Correct |
19 ms |
15228 KB |
Output is correct |
48 |
Correct |
150 ms |
45500 KB |
Output is correct |
49 |
Correct |
172 ms |
45612 KB |
Output is correct |
50 |
Correct |
175 ms |
45500 KB |
Output is correct |
51 |
Correct |
160 ms |
45252 KB |
Output is correct |
52 |
Correct |
155 ms |
43556 KB |
Output is correct |
53 |
Correct |
123 ms |
36520 KB |
Output is correct |
54 |
Correct |
177 ms |
46224 KB |
Output is correct |
55 |
Correct |
156 ms |
45500 KB |
Output is correct |
56 |
Correct |
188 ms |
47548 KB |
Output is correct |
57 |
Correct |
182 ms |
46480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
10832 KB |
Output is correct |
2 |
Correct |
5 ms |
10832 KB |
Output is correct |
3 |
Correct |
5 ms |
10832 KB |
Output is correct |
4 |
Correct |
5 ms |
11000 KB |
Output is correct |
5 |
Correct |
5 ms |
10920 KB |
Output is correct |
6 |
Correct |
6 ms |
11088 KB |
Output is correct |
7 |
Correct |
5 ms |
11088 KB |
Output is correct |
8 |
Correct |
7 ms |
11088 KB |
Output is correct |
9 |
Correct |
6 ms |
11088 KB |
Output is correct |
10 |
Correct |
88 ms |
33724 KB |
Output is correct |
11 |
Correct |
98 ms |
38788 KB |
Output is correct |
12 |
Correct |
98 ms |
38332 KB |
Output is correct |
13 |
Correct |
107 ms |
39868 KB |
Output is correct |
14 |
Correct |
111 ms |
41916 KB |
Output is correct |
15 |
Correct |
76 ms |
33800 KB |
Output is correct |
16 |
Correct |
150 ms |
40380 KB |
Output is correct |
17 |
Correct |
145 ms |
39612 KB |
Output is correct |
18 |
Correct |
153 ms |
41404 KB |
Output is correct |
19 |
Correct |
174 ms |
43452 KB |
Output is correct |
20 |
Correct |
183 ms |
43784 KB |
Output is correct |
21 |
Correct |
171 ms |
45456 KB |
Output is correct |
22 |
Correct |
177 ms |
44524 KB |
Output is correct |
23 |
Correct |
172 ms |
45096 KB |
Output is correct |
24 |
Correct |
193 ms |
44992 KB |
Output is correct |
25 |
Correct |
159 ms |
43552 KB |
Output is correct |
26 |
Correct |
167 ms |
44736 KB |
Output is correct |
27 |
Correct |
164 ms |
43316 KB |
Output is correct |
28 |
Correct |
5 ms |
11088 KB |
Output is correct |
29 |
Correct |
5 ms |
11088 KB |
Output is correct |
30 |
Correct |
5 ms |
11100 KB |
Output is correct |
31 |
Correct |
5 ms |
11088 KB |
Output is correct |
32 |
Correct |
5 ms |
11088 KB |
Output is correct |
33 |
Correct |
5 ms |
11088 KB |
Output is correct |
34 |
Correct |
5 ms |
11088 KB |
Output is correct |
35 |
Correct |
5 ms |
11088 KB |
Output is correct |
36 |
Correct |
5 ms |
11088 KB |
Output is correct |
37 |
Correct |
14 ms |
15288 KB |
Output is correct |
38 |
Correct |
95 ms |
41660 KB |
Output is correct |
39 |
Correct |
101 ms |
41660 KB |
Output is correct |
40 |
Correct |
102 ms |
41664 KB |
Output is correct |
41 |
Correct |
99 ms |
41172 KB |
Output is correct |
42 |
Correct |
92 ms |
40976 KB |
Output is correct |
43 |
Correct |
86 ms |
38640 KB |
Output is correct |
44 |
Correct |
108 ms |
41916 KB |
Output is correct |
45 |
Correct |
97 ms |
41700 KB |
Output is correct |
46 |
Correct |
96 ms |
44220 KB |
Output is correct |
47 |
Correct |
99 ms |
41916 KB |
Output is correct |
48 |
Correct |
19 ms |
15228 KB |
Output is correct |
49 |
Correct |
150 ms |
45500 KB |
Output is correct |
50 |
Correct |
172 ms |
45612 KB |
Output is correct |
51 |
Correct |
175 ms |
45500 KB |
Output is correct |
52 |
Correct |
160 ms |
45252 KB |
Output is correct |
53 |
Correct |
155 ms |
43556 KB |
Output is correct |
54 |
Correct |
123 ms |
36520 KB |
Output is correct |
55 |
Correct |
177 ms |
46224 KB |
Output is correct |
56 |
Correct |
156 ms |
45500 KB |
Output is correct |
57 |
Correct |
188 ms |
47548 KB |
Output is correct |
58 |
Correct |
182 ms |
46480 KB |
Output is correct |
59 |
Correct |
61 ms |
18776 KB |
Output is correct |
60 |
Correct |
159 ms |
40844 KB |
Output is correct |
61 |
Correct |
156 ms |
40188 KB |
Output is correct |
62 |
Correct |
161 ms |
41904 KB |
Output is correct |
63 |
Correct |
205 ms |
43920 KB |
Output is correct |
64 |
Correct |
5 ms |
11088 KB |
Output is correct |
65 |
Correct |
6 ms |
11088 KB |
Output is correct |
66 |
Correct |
5 ms |
11088 KB |
Output is correct |
67 |
Correct |
5 ms |
11088 KB |
Output is correct |
68 |
Correct |
5 ms |
11088 KB |
Output is correct |
69 |
Correct |
5 ms |
11088 KB |
Output is correct |
70 |
Correct |
5 ms |
11344 KB |
Output is correct |
71 |
Correct |
6 ms |
11088 KB |
Output is correct |
72 |
Correct |
5 ms |
11088 KB |
Output is correct |
73 |
Correct |
6 ms |
11088 KB |
Output is correct |
74 |
Correct |
104 ms |
40372 KB |
Output is correct |
75 |
Correct |
96 ms |
41668 KB |
Output is correct |
76 |
Correct |
97 ms |
41660 KB |
Output is correct |
77 |
Correct |
110 ms |
42428 KB |
Output is correct |
78 |
Correct |
51 ms |
19664 KB |
Output is correct |
79 |
Correct |
44 ms |
19228 KB |
Output is correct |
80 |
Correct |
82 ms |
35004 KB |
Output is correct |
81 |
Correct |
120 ms |
45552 KB |
Output is correct |
82 |
Correct |
163 ms |
51784 KB |
Output is correct |
83 |
Correct |
129 ms |
47416 KB |
Output is correct |
84 |
Correct |
104 ms |
44032 KB |
Output is correct |
85 |
Correct |
143 ms |
47296 KB |
Output is correct |
86 |
Correct |
61 ms |
22976 KB |
Output is correct |
87 |
Correct |
167 ms |
45624 KB |
Output is correct |
88 |
Correct |
182 ms |
45508 KB |
Output is correct |
89 |
Correct |
195 ms |
44652 KB |
Output is correct |
90 |
Correct |
107 ms |
23736 KB |
Output is correct |
91 |
Correct |
125 ms |
25948 KB |
Output is correct |
92 |
Correct |
157 ms |
38844 KB |
Output is correct |
93 |
Correct |
213 ms |
49332 KB |
Output is correct |
94 |
Correct |
210 ms |
54196 KB |
Output is correct |
95 |
Correct |
185 ms |
51124 KB |
Output is correct |
96 |
Correct |
205 ms |
47808 KB |
Output is correct |
97 |
Correct |
199 ms |
49332 KB |
Output is correct |