#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int deg[100005], par[100005], sz[100005], w1[100005], w2[100005];
vector<pair<int, pair<int, int> > > edge;
int findPar(int x)
{
return (par[x]==x)?x:findPar(par[x]);
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w)
{
// cout << "init\n";
for (int i=0; i<m; i++)
edge.push_back({w[i], {u[i], v[i]}});
sort(edge.begin(), edge.end());
for (int i=0; i<n; i++)
{
par[i]=i;
sz[i]=1;
w1[i]=w2[i]=2e9;
}
for (int i=0; i<m; i++)
{
int x=edge[i].second.first, y=edge[i].second.second, z=edge[i].first;
bool bridge=(deg[x]>=2 || deg[y]>=2);
deg[x]++;
deg[y]++;
x=findPar(x);
y=findPar(y);
if (x==y)
{
w2[y]=min(w2[y], z);
continue;
}
if (sz[x]>sz[y])
swap(x, y);
par[x]=y;
// cout << "par[" << x << "]=" << y << '\n';
sz[y]+=sz[x];
w1[x]=z;
if (bridge || w2[x]<2e9)
w2[y]=min(w2[y], z);
}
// cout << "initend\n";
}
int getMinimumFuelCapacity(int x, int y)
{
int ans=0;
while (x!=y)
{
// cout << "x y " << x << ' ' << y << '\n';
// cout << "w1[x] w1[y] " << w1[x] << ' ' << w1[y] << '\n';
if (w1[x]<w1[y])
{
ans=w1[x];
x=par[x];
}
else
{
ans=w1[y];
y=par[y];
}
}
while (par[x]!=x)
{
if (w2[x]<2e9)
return max(ans, w2[x]);
ans=w1[x];
x=par[x];
}
if (w2[x]<2e9)
return max(ans, w2[x]);
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
4684 KB |
Output is correct |
10 |
Correct |
43 ms |
5652 KB |
Output is correct |
11 |
Correct |
39 ms |
5584 KB |
Output is correct |
12 |
Correct |
42 ms |
5828 KB |
Output is correct |
13 |
Correct |
41 ms |
5880 KB |
Output is correct |
14 |
Correct |
38 ms |
4768 KB |
Output is correct |
15 |
Correct |
109 ms |
7468 KB |
Output is correct |
16 |
Correct |
108 ms |
7408 KB |
Output is correct |
17 |
Correct |
107 ms |
7592 KB |
Output is correct |
18 |
Correct |
94 ms |
7604 KB |
Output is correct |
19 |
Correct |
57 ms |
4748 KB |
Output is correct |
20 |
Correct |
106 ms |
8532 KB |
Output is correct |
21 |
Correct |
109 ms |
8752 KB |
Output is correct |
22 |
Correct |
114 ms |
9028 KB |
Output is correct |
23 |
Correct |
101 ms |
9088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
89 ms |
8476 KB |
Output is correct |
4 |
Correct |
91 ms |
8516 KB |
Output is correct |
5 |
Correct |
109 ms |
8904 KB |
Output is correct |
6 |
Correct |
85 ms |
8500 KB |
Output is correct |
7 |
Correct |
90 ms |
8748 KB |
Output is correct |
8 |
Correct |
86 ms |
8460 KB |
Output is correct |
9 |
Correct |
89 ms |
8640 KB |
Output is correct |
10 |
Correct |
90 ms |
8476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
320 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 |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
360 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
34 ms |
4684 KB |
Output is correct |
11 |
Correct |
43 ms |
5652 KB |
Output is correct |
12 |
Correct |
39 ms |
5584 KB |
Output is correct |
13 |
Correct |
42 ms |
5828 KB |
Output is correct |
14 |
Correct |
41 ms |
5880 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
460 KB |
Output is correct |
34 |
Correct |
6 ms |
1428 KB |
Output is correct |
35 |
Correct |
43 ms |
7720 KB |
Output is correct |
36 |
Correct |
40 ms |
7744 KB |
Output is correct |
37 |
Correct |
40 ms |
7616 KB |
Output is correct |
38 |
Correct |
39 ms |
7600 KB |
Output is correct |
39 |
Correct |
40 ms |
7584 KB |
Output is correct |
40 |
Correct |
36 ms |
6980 KB |
Output is correct |
41 |
Correct |
43 ms |
8000 KB |
Output is correct |
42 |
Correct |
41 ms |
7728 KB |
Output is correct |
43 |
Correct |
39 ms |
7740 KB |
Output is correct |
44 |
Correct |
43 ms |
8000 KB |
Output is correct |
45 |
Correct |
66 ms |
10200 KB |
Output is correct |
46 |
Correct |
50 ms |
7732 KB |
Output is correct |
47 |
Correct |
43 ms |
7752 KB |
Output is correct |
48 |
Correct |
44 ms |
8244 KB |
Output is correct |
49 |
Correct |
59 ms |
9920 KB |
Output is correct |
50 |
Correct |
51 ms |
7124 KB |
Output is correct |
51 |
Correct |
55 ms |
8936 KB |
Output is correct |
52 |
Correct |
78 ms |
11396 KB |
Output is correct |
53 |
Correct |
80 ms |
12364 KB |
Output is correct |
54 |
Correct |
91 ms |
13392 KB |
Output is correct |
55 |
Correct |
39 ms |
7744 KB |
Output is correct |
56 |
Correct |
74 ms |
12028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
4684 KB |
Output is correct |
10 |
Correct |
43 ms |
5652 KB |
Output is correct |
11 |
Correct |
39 ms |
5584 KB |
Output is correct |
12 |
Correct |
42 ms |
5828 KB |
Output is correct |
13 |
Correct |
41 ms |
5880 KB |
Output is correct |
14 |
Correct |
38 ms |
4768 KB |
Output is correct |
15 |
Correct |
109 ms |
7468 KB |
Output is correct |
16 |
Correct |
108 ms |
7408 KB |
Output is correct |
17 |
Correct |
107 ms |
7592 KB |
Output is correct |
18 |
Correct |
94 ms |
7604 KB |
Output is correct |
19 |
Correct |
89 ms |
8476 KB |
Output is correct |
20 |
Correct |
91 ms |
8516 KB |
Output is correct |
21 |
Correct |
109 ms |
8904 KB |
Output is correct |
22 |
Correct |
85 ms |
8500 KB |
Output is correct |
23 |
Correct |
90 ms |
8748 KB |
Output is correct |
24 |
Correct |
86 ms |
8460 KB |
Output is correct |
25 |
Correct |
89 ms |
8640 KB |
Output is correct |
26 |
Correct |
90 ms |
8476 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
324 KB |
Output is correct |
33 |
Correct |
1 ms |
320 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
36 |
Correct |
6 ms |
1428 KB |
Output is correct |
37 |
Correct |
43 ms |
7720 KB |
Output is correct |
38 |
Correct |
40 ms |
7744 KB |
Output is correct |
39 |
Correct |
40 ms |
7616 KB |
Output is correct |
40 |
Correct |
39 ms |
7600 KB |
Output is correct |
41 |
Correct |
40 ms |
7584 KB |
Output is correct |
42 |
Correct |
36 ms |
6980 KB |
Output is correct |
43 |
Correct |
43 ms |
8000 KB |
Output is correct |
44 |
Correct |
41 ms |
7728 KB |
Output is correct |
45 |
Correct |
39 ms |
7740 KB |
Output is correct |
46 |
Correct |
43 ms |
8000 KB |
Output is correct |
47 |
Correct |
11 ms |
1892 KB |
Output is correct |
48 |
Correct |
108 ms |
12692 KB |
Output is correct |
49 |
Correct |
116 ms |
12600 KB |
Output is correct |
50 |
Correct |
109 ms |
12584 KB |
Output is correct |
51 |
Correct |
108 ms |
12548 KB |
Output is correct |
52 |
Correct |
104 ms |
12124 KB |
Output is correct |
53 |
Correct |
98 ms |
11212 KB |
Output is correct |
54 |
Correct |
116 ms |
13436 KB |
Output is correct |
55 |
Correct |
116 ms |
12508 KB |
Output is correct |
56 |
Correct |
95 ms |
12576 KB |
Output is correct |
57 |
Correct |
117 ms |
13416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
34 ms |
4684 KB |
Output is correct |
11 |
Correct |
43 ms |
5652 KB |
Output is correct |
12 |
Correct |
39 ms |
5584 KB |
Output is correct |
13 |
Correct |
42 ms |
5828 KB |
Output is correct |
14 |
Correct |
41 ms |
5880 KB |
Output is correct |
15 |
Correct |
38 ms |
4768 KB |
Output is correct |
16 |
Correct |
109 ms |
7468 KB |
Output is correct |
17 |
Correct |
108 ms |
7408 KB |
Output is correct |
18 |
Correct |
107 ms |
7592 KB |
Output is correct |
19 |
Correct |
94 ms |
7604 KB |
Output is correct |
20 |
Correct |
89 ms |
8476 KB |
Output is correct |
21 |
Correct |
91 ms |
8516 KB |
Output is correct |
22 |
Correct |
109 ms |
8904 KB |
Output is correct |
23 |
Correct |
85 ms |
8500 KB |
Output is correct |
24 |
Correct |
90 ms |
8748 KB |
Output is correct |
25 |
Correct |
86 ms |
8460 KB |
Output is correct |
26 |
Correct |
89 ms |
8640 KB |
Output is correct |
27 |
Correct |
90 ms |
8476 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 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 |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
324 KB |
Output is correct |
37 |
Correct |
6 ms |
1428 KB |
Output is correct |
38 |
Correct |
43 ms |
7720 KB |
Output is correct |
39 |
Correct |
40 ms |
7744 KB |
Output is correct |
40 |
Correct |
40 ms |
7616 KB |
Output is correct |
41 |
Correct |
39 ms |
7600 KB |
Output is correct |
42 |
Correct |
40 ms |
7584 KB |
Output is correct |
43 |
Correct |
36 ms |
6980 KB |
Output is correct |
44 |
Correct |
43 ms |
8000 KB |
Output is correct |
45 |
Correct |
41 ms |
7728 KB |
Output is correct |
46 |
Correct |
39 ms |
7740 KB |
Output is correct |
47 |
Correct |
43 ms |
8000 KB |
Output is correct |
48 |
Correct |
11 ms |
1892 KB |
Output is correct |
49 |
Correct |
108 ms |
12692 KB |
Output is correct |
50 |
Correct |
116 ms |
12600 KB |
Output is correct |
51 |
Correct |
109 ms |
12584 KB |
Output is correct |
52 |
Correct |
108 ms |
12548 KB |
Output is correct |
53 |
Correct |
104 ms |
12124 KB |
Output is correct |
54 |
Correct |
98 ms |
11212 KB |
Output is correct |
55 |
Correct |
116 ms |
13436 KB |
Output is correct |
56 |
Correct |
116 ms |
12508 KB |
Output is correct |
57 |
Correct |
95 ms |
12576 KB |
Output is correct |
58 |
Correct |
117 ms |
13416 KB |
Output is correct |
59 |
Correct |
57 ms |
4748 KB |
Output is correct |
60 |
Correct |
106 ms |
8532 KB |
Output is correct |
61 |
Correct |
109 ms |
8752 KB |
Output is correct |
62 |
Correct |
114 ms |
9028 KB |
Output is correct |
63 |
Correct |
101 ms |
9088 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
324 KB |
Output is correct |
66 |
Correct |
1 ms |
460 KB |
Output is correct |
67 |
Correct |
1 ms |
360 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
460 KB |
Output is correct |
74 |
Correct |
66 ms |
10200 KB |
Output is correct |
75 |
Correct |
50 ms |
7732 KB |
Output is correct |
76 |
Correct |
43 ms |
7752 KB |
Output is correct |
77 |
Correct |
44 ms |
8244 KB |
Output is correct |
78 |
Correct |
59 ms |
9920 KB |
Output is correct |
79 |
Correct |
51 ms |
7124 KB |
Output is correct |
80 |
Correct |
55 ms |
8936 KB |
Output is correct |
81 |
Correct |
78 ms |
11396 KB |
Output is correct |
82 |
Correct |
80 ms |
12364 KB |
Output is correct |
83 |
Correct |
91 ms |
13392 KB |
Output is correct |
84 |
Correct |
39 ms |
7744 KB |
Output is correct |
85 |
Correct |
74 ms |
12028 KB |
Output is correct |
86 |
Correct |
38 ms |
4720 KB |
Output is correct |
87 |
Correct |
113 ms |
12604 KB |
Output is correct |
88 |
Correct |
108 ms |
12580 KB |
Output is correct |
89 |
Correct |
100 ms |
12640 KB |
Output is correct |
90 |
Correct |
139 ms |
13756 KB |
Output is correct |
91 |
Correct |
120 ms |
13464 KB |
Output is correct |
92 |
Correct |
112 ms |
13752 KB |
Output is correct |
93 |
Correct |
136 ms |
15928 KB |
Output is correct |
94 |
Correct |
138 ms |
16784 KB |
Output is correct |
95 |
Correct |
161 ms |
17228 KB |
Output is correct |
96 |
Correct |
100 ms |
12736 KB |
Output is correct |
97 |
Correct |
124 ms |
14904 KB |
Output is correct |