#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define w first
#define u second.first
#define v second.second
struct x{
lli padre;
lli flag;
lli prof;
lli val;
lli l;
lli r;
};
lli dis[MAX+2];
lli n,m,a,b,res;
vector< pair<lli, pair<lli,lli> > > orden;
x uf[MAX+2];
lli dfs(lli pos) {
if (dis[pos] > 0) return dis[pos]+1;
if (uf[pos].padre == pos) {
dis[pos] = 1;
return 2;
}
dis[pos] = dfs(uf[pos].padre);
return dis[pos]+1;
}
void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N;
m = M;
rep(i,0,m-1) orden.push_back({W[i], {U[i]+1,V[i]+1} });
sort(orden.begin(), orden.end());
rep(i,1,n) uf[i] = {i,0,1,0,i,i};
for (auto act : orden) {
a = uf[act.u].padre;
while (a != uf[a].padre) a = uf[a].padre;
b = uf[act.v].padre;
while (b != uf[b].padre) b = uf[b].padre;
if (a == b) {
if (uf[a].flag) continue;
uf[a].flag = act.w;
}
else {
if (uf[b].prof > uf[a].prof) {
swap(a,b);
swap(act.u, act.v);
}
uf[b].val = act.w;
uf[b].padre = a;
if (uf[b].prof == uf[a].prof) uf[a].prof++;
if (uf[a].flag) continue;
if (uf[b].flag) uf[a].flag = act.w;
else {
if (uf[a].l == act.u && uf[b].l == act.v) uf[a].l = uf[b].r;
else if (uf[a].l == act.u && uf[b].r == act.v) uf[a].l = uf[b].l;
else if (uf[a].r == act.u && uf[b].l == act.v) uf[a].r = uf[b].r;
else if (uf[a].r == act.u && uf[b].r == act.v) uf[a].r = uf[b].l;
else {
uf[a].flag = act.w;
}
}
}
}
rep(i,1,n) if (dis[i] == 0) {
if (uf[i].padre == i) dis[i] = 1;
else dis[i] = dfs(uf[i].padre);
}
}
int getMinimumFuelCapacity(int X, int Y) {
X++;
Y++;
if (dis[X] < dis[Y]) swap(X,Y);
a = dis[X] - dis[Y];
res = -1;
rep(i,1,a) {
res = max(res,uf[X].val);
X = uf[X].padre;
}
while (X != Y) {
res = max(res,uf[X].val);
X = uf[X].padre;
res = max(res,uf[Y].val);
Y = uf[Y].padre;
}
while (uf[X].flag == 0) {
res = max(res,uf[X].val);
if (X != uf[X].padre) X = uf[X].padre;
else return -1;
}
res = max(res,uf[X].flag);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
47 ms |
8508 KB |
Output is correct |
10 |
Correct |
49 ms |
10248 KB |
Output is correct |
11 |
Correct |
47 ms |
10092 KB |
Output is correct |
12 |
Correct |
49 ms |
10696 KB |
Output is correct |
13 |
Correct |
46 ms |
10652 KB |
Output is correct |
14 |
Correct |
47 ms |
8636 KB |
Output is correct |
15 |
Correct |
137 ms |
11996 KB |
Output is correct |
16 |
Correct |
136 ms |
11812 KB |
Output is correct |
17 |
Correct |
122 ms |
12388 KB |
Output is correct |
18 |
Correct |
141 ms |
12328 KB |
Output is correct |
19 |
Correct |
79 ms |
5580 KB |
Output is correct |
20 |
Correct |
122 ms |
13132 KB |
Output is correct |
21 |
Correct |
134 ms |
13120 KB |
Output is correct |
22 |
Correct |
134 ms |
13696 KB |
Output is correct |
23 |
Correct |
106 ms |
13860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
108 ms |
13156 KB |
Output is correct |
4 |
Correct |
101 ms |
13476 KB |
Output is correct |
5 |
Correct |
108 ms |
13596 KB |
Output is correct |
6 |
Correct |
99 ms |
13364 KB |
Output is correct |
7 |
Correct |
102 ms |
13624 KB |
Output is correct |
8 |
Correct |
105 ms |
13188 KB |
Output is correct |
9 |
Correct |
105 ms |
13352 KB |
Output is correct |
10 |
Correct |
101 ms |
13060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
448 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
320 KB |
Output is correct |
20 |
Correct |
2 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
452 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
448 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
448 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
47 ms |
8508 KB |
Output is correct |
11 |
Correct |
49 ms |
10248 KB |
Output is correct |
12 |
Correct |
47 ms |
10092 KB |
Output is correct |
13 |
Correct |
49 ms |
10696 KB |
Output is correct |
14 |
Correct |
46 ms |
10652 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
456 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
448 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
320 KB |
Output is correct |
25 |
Correct |
2 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
448 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
448 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
9 ms |
2000 KB |
Output is correct |
35 |
Correct |
61 ms |
12060 KB |
Output is correct |
36 |
Correct |
51 ms |
12084 KB |
Output is correct |
37 |
Correct |
48 ms |
12336 KB |
Output is correct |
38 |
Correct |
52 ms |
12200 KB |
Output is correct |
39 |
Correct |
45 ms |
12188 KB |
Output is correct |
40 |
Correct |
43 ms |
11212 KB |
Output is correct |
41 |
Correct |
49 ms |
12712 KB |
Output is correct |
42 |
Correct |
48 ms |
12344 KB |
Output is correct |
43 |
Correct |
51 ms |
12336 KB |
Output is correct |
44 |
Correct |
52 ms |
12720 KB |
Output is correct |
45 |
Correct |
70 ms |
14676 KB |
Output is correct |
46 |
Correct |
54 ms |
12328 KB |
Output is correct |
47 |
Correct |
47 ms |
12408 KB |
Output is correct |
48 |
Correct |
60 ms |
12984 KB |
Output is correct |
49 |
Correct |
64 ms |
13056 KB |
Output is correct |
50 |
Correct |
50 ms |
8764 KB |
Output is correct |
51 |
Correct |
58 ms |
12632 KB |
Output is correct |
52 |
Correct |
81 ms |
15940 KB |
Output is correct |
53 |
Correct |
82 ms |
16700 KB |
Output is correct |
54 |
Correct |
101 ms |
17692 KB |
Output is correct |
55 |
Correct |
59 ms |
12356 KB |
Output is correct |
56 |
Correct |
80 ms |
16368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
47 ms |
8508 KB |
Output is correct |
10 |
Correct |
49 ms |
10248 KB |
Output is correct |
11 |
Correct |
47 ms |
10092 KB |
Output is correct |
12 |
Correct |
49 ms |
10696 KB |
Output is correct |
13 |
Correct |
46 ms |
10652 KB |
Output is correct |
14 |
Correct |
47 ms |
8636 KB |
Output is correct |
15 |
Correct |
137 ms |
11996 KB |
Output is correct |
16 |
Correct |
136 ms |
11812 KB |
Output is correct |
17 |
Correct |
122 ms |
12388 KB |
Output is correct |
18 |
Correct |
141 ms |
12328 KB |
Output is correct |
19 |
Correct |
108 ms |
13156 KB |
Output is correct |
20 |
Correct |
101 ms |
13476 KB |
Output is correct |
21 |
Correct |
108 ms |
13596 KB |
Output is correct |
22 |
Correct |
99 ms |
13364 KB |
Output is correct |
23 |
Correct |
102 ms |
13624 KB |
Output is correct |
24 |
Correct |
105 ms |
13188 KB |
Output is correct |
25 |
Correct |
105 ms |
13352 KB |
Output is correct |
26 |
Correct |
101 ms |
13060 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
456 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
448 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
2000 KB |
Output is correct |
37 |
Correct |
61 ms |
12060 KB |
Output is correct |
38 |
Correct |
51 ms |
12084 KB |
Output is correct |
39 |
Correct |
48 ms |
12336 KB |
Output is correct |
40 |
Correct |
52 ms |
12200 KB |
Output is correct |
41 |
Correct |
45 ms |
12188 KB |
Output is correct |
42 |
Correct |
43 ms |
11212 KB |
Output is correct |
43 |
Correct |
49 ms |
12712 KB |
Output is correct |
44 |
Correct |
48 ms |
12344 KB |
Output is correct |
45 |
Correct |
51 ms |
12336 KB |
Output is correct |
46 |
Correct |
52 ms |
12720 KB |
Output is correct |
47 |
Correct |
12 ms |
2376 KB |
Output is correct |
48 |
Correct |
117 ms |
15364 KB |
Output is correct |
49 |
Correct |
128 ms |
15496 KB |
Output is correct |
50 |
Correct |
122 ms |
15464 KB |
Output is correct |
51 |
Correct |
121 ms |
15368 KB |
Output is correct |
52 |
Correct |
130 ms |
14880 KB |
Output is correct |
53 |
Correct |
100 ms |
13096 KB |
Output is correct |
54 |
Correct |
121 ms |
16056 KB |
Output is correct |
55 |
Correct |
140 ms |
15492 KB |
Output is correct |
56 |
Correct |
98 ms |
15424 KB |
Output is correct |
57 |
Correct |
121 ms |
16052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
47 ms |
8508 KB |
Output is correct |
11 |
Correct |
49 ms |
10248 KB |
Output is correct |
12 |
Correct |
47 ms |
10092 KB |
Output is correct |
13 |
Correct |
49 ms |
10696 KB |
Output is correct |
14 |
Correct |
46 ms |
10652 KB |
Output is correct |
15 |
Correct |
47 ms |
8636 KB |
Output is correct |
16 |
Correct |
137 ms |
11996 KB |
Output is correct |
17 |
Correct |
136 ms |
11812 KB |
Output is correct |
18 |
Correct |
122 ms |
12388 KB |
Output is correct |
19 |
Correct |
141 ms |
12328 KB |
Output is correct |
20 |
Correct |
108 ms |
13156 KB |
Output is correct |
21 |
Correct |
101 ms |
13476 KB |
Output is correct |
22 |
Correct |
108 ms |
13596 KB |
Output is correct |
23 |
Correct |
99 ms |
13364 KB |
Output is correct |
24 |
Correct |
102 ms |
13624 KB |
Output is correct |
25 |
Correct |
105 ms |
13188 KB |
Output is correct |
26 |
Correct |
105 ms |
13352 KB |
Output is correct |
27 |
Correct |
101 ms |
13060 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
448 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
9 ms |
2000 KB |
Output is correct |
38 |
Correct |
61 ms |
12060 KB |
Output is correct |
39 |
Correct |
51 ms |
12084 KB |
Output is correct |
40 |
Correct |
48 ms |
12336 KB |
Output is correct |
41 |
Correct |
52 ms |
12200 KB |
Output is correct |
42 |
Correct |
45 ms |
12188 KB |
Output is correct |
43 |
Correct |
43 ms |
11212 KB |
Output is correct |
44 |
Correct |
49 ms |
12712 KB |
Output is correct |
45 |
Correct |
48 ms |
12344 KB |
Output is correct |
46 |
Correct |
51 ms |
12336 KB |
Output is correct |
47 |
Correct |
52 ms |
12720 KB |
Output is correct |
48 |
Correct |
12 ms |
2376 KB |
Output is correct |
49 |
Correct |
117 ms |
15364 KB |
Output is correct |
50 |
Correct |
128 ms |
15496 KB |
Output is correct |
51 |
Correct |
122 ms |
15464 KB |
Output is correct |
52 |
Correct |
121 ms |
15368 KB |
Output is correct |
53 |
Correct |
130 ms |
14880 KB |
Output is correct |
54 |
Correct |
100 ms |
13096 KB |
Output is correct |
55 |
Correct |
121 ms |
16056 KB |
Output is correct |
56 |
Correct |
140 ms |
15492 KB |
Output is correct |
57 |
Correct |
98 ms |
15424 KB |
Output is correct |
58 |
Correct |
121 ms |
16052 KB |
Output is correct |
59 |
Correct |
79 ms |
5580 KB |
Output is correct |
60 |
Correct |
122 ms |
13132 KB |
Output is correct |
61 |
Correct |
134 ms |
13120 KB |
Output is correct |
62 |
Correct |
134 ms |
13696 KB |
Output is correct |
63 |
Correct |
106 ms |
13860 KB |
Output is correct |
64 |
Correct |
2 ms |
320 KB |
Output is correct |
65 |
Correct |
2 ms |
448 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
2 ms |
452 KB |
Output is correct |
68 |
Correct |
2 ms |
340 KB |
Output is correct |
69 |
Correct |
2 ms |
448 KB |
Output is correct |
70 |
Correct |
2 ms |
468 KB |
Output is correct |
71 |
Correct |
2 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
448 KB |
Output is correct |
73 |
Correct |
2 ms |
468 KB |
Output is correct |
74 |
Correct |
70 ms |
14676 KB |
Output is correct |
75 |
Correct |
54 ms |
12328 KB |
Output is correct |
76 |
Correct |
47 ms |
12408 KB |
Output is correct |
77 |
Correct |
60 ms |
12984 KB |
Output is correct |
78 |
Correct |
64 ms |
13056 KB |
Output is correct |
79 |
Correct |
50 ms |
8764 KB |
Output is correct |
80 |
Correct |
58 ms |
12632 KB |
Output is correct |
81 |
Correct |
81 ms |
15940 KB |
Output is correct |
82 |
Correct |
82 ms |
16700 KB |
Output is correct |
83 |
Correct |
101 ms |
17692 KB |
Output is correct |
84 |
Correct |
59 ms |
12356 KB |
Output is correct |
85 |
Correct |
80 ms |
16368 KB |
Output is correct |
86 |
Correct |
38 ms |
6456 KB |
Output is correct |
87 |
Correct |
135 ms |
15488 KB |
Output is correct |
88 |
Correct |
111 ms |
15388 KB |
Output is correct |
89 |
Correct |
122 ms |
15112 KB |
Output is correct |
90 |
Correct |
144 ms |
14404 KB |
Output is correct |
91 |
Correct |
119 ms |
14108 KB |
Output is correct |
92 |
Correct |
120 ms |
14856 KB |
Output is correct |
93 |
Correct |
160 ms |
18060 KB |
Output is correct |
94 |
Correct |
140 ms |
18736 KB |
Output is correct |
95 |
Correct |
199 ms |
19260 KB |
Output is correct |
96 |
Correct |
108 ms |
15512 KB |
Output is correct |
97 |
Correct |
123 ms |
17276 KB |
Output is correct |