#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
const int N = 100005;
vec<pair<int, int>> hist[N];
vec<int> okt(N, -1);
const int INF = 1e9+5;
struct Comp {
pair<int, int> eps;
vec<int> vs;
};
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
vec<Comp> comps(N);
for(int i = 0; i<N; i++) {
comps[i] = {{i, i}, {i}};
hist[i] = {{i, 0}};
}
set<pair<int, pair<int, int>>> edges;
for(int i = 0; i<M; i++) {
edges.insert({W[i], {U[i], V[i]}});
}
vec<int> ci(N);
iota(ci.begin(), ci.end(), 0);
auto upd = [&](int i, int w) {
if(okt[i] != -1) return;
okt[i] = w;
};
for(auto [weight, eps] : edges) {
auto [u, v] = eps;
if(ci[u] == ci[v]) {
upd(ci[u], weight);
continue;
}
if(comps[ci[u]].vs.size() < comps[ci[v]].vs.size()) swap(u, v);
if(u == comps[ci[u]].eps.second) swap(comps[ci[u]].eps.first, comps[ci[u]].eps.second);
if(v == comps[ci[v]].eps.second) swap(comps[ci[v]].eps.first, comps[ci[v]].eps.second);
if(okt[ci[v]] == -1 && u == comps[ci[u]].eps.first && v == comps[ci[v]].eps.first) {
comps[ci[u]].eps = {comps[ci[u]].eps.second, comps[ci[v]].eps.second};
}
else {
upd(ci[u], weight);
}
for(int w : comps[ci[v]].vs) {
ci[w] = ci[u];
comps[ci[u]].vs.push_back(w);
hist[w].push_back({ci[u], weight});
}
}
for(int i = 0; i<N; i++) {
hist[i].push_back({-1, INF});
}
}
int getMinimumFuelCapacity(int X, int Y) {
int i = 0;
int j = 0;
//cerr << okt[1] << '\n';
while(i<hist[X].size() && j < hist[Y].size()) {
if(hist[X][i].first == hist[Y][j].first && okt[hist[X][i].first] != -1) {
return max(max(hist[X][i].second, hist[Y][j].second), okt[hist[X][i].first]);
}
if(hist[X][i+1].second < hist[Y][j+1].second) {
i++;
}
else {
j++;
}
}
return -1;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:78:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while(i<hist[X].size() && j < hist[Y].size()) {
| ~^~~~~~~~~~~~~~~
swap.cpp:78:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while(i<hist[X].size() && j < hist[Y].size()) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
97 ms |
29060 KB |
Output is correct |
10 |
Correct |
121 ms |
34540 KB |
Output is correct |
11 |
Correct |
112 ms |
33824 KB |
Output is correct |
12 |
Correct |
156 ms |
35920 KB |
Output is correct |
13 |
Correct |
92 ms |
28848 KB |
Output is correct |
14 |
Correct |
101 ms |
29156 KB |
Output is correct |
15 |
Correct |
187 ms |
39004 KB |
Output is correct |
16 |
Correct |
175 ms |
37828 KB |
Output is correct |
17 |
Correct |
188 ms |
40196 KB |
Output is correct |
18 |
Correct |
144 ms |
32712 KB |
Output is correct |
19 |
Correct |
51 ms |
11876 KB |
Output is correct |
20 |
Correct |
181 ms |
38728 KB |
Output is correct |
21 |
Correct |
181 ms |
37836 KB |
Output is correct |
22 |
Correct |
180 ms |
40044 KB |
Output is correct |
23 |
Correct |
151 ms |
32840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
130 ms |
30668 KB |
Output is correct |
4 |
Correct |
134 ms |
31776 KB |
Output is correct |
5 |
Correct |
117 ms |
31176 KB |
Output is correct |
6 |
Correct |
126 ms |
31732 KB |
Output is correct |
7 |
Correct |
165 ms |
31560 KB |
Output is correct |
8 |
Correct |
114 ms |
30416 KB |
Output is correct |
9 |
Correct |
129 ms |
31204 KB |
Output is correct |
10 |
Correct |
126 ms |
30156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3452 KB |
Output is correct |
12 |
Correct |
2 ms |
3420 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3420 KB |
Output is correct |
15 |
Correct |
3 ms |
3420 KB |
Output is correct |
16 |
Correct |
2 ms |
3460 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
2 ms |
3224 KB |
Output is correct |
20 |
Correct |
3 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3420 KB |
Output is correct |
22 |
Correct |
3 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3420 KB |
Output is correct |
27 |
Correct |
2 ms |
3420 KB |
Output is correct |
28 |
Correct |
3 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3420 KB |
Output is correct |
10 |
Correct |
97 ms |
29060 KB |
Output is correct |
11 |
Correct |
121 ms |
34540 KB |
Output is correct |
12 |
Correct |
112 ms |
33824 KB |
Output is correct |
13 |
Correct |
156 ms |
35920 KB |
Output is correct |
14 |
Correct |
92 ms |
28848 KB |
Output is correct |
15 |
Correct |
2 ms |
3420 KB |
Output is correct |
16 |
Correct |
2 ms |
3452 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
2 ms |
3420 KB |
Output is correct |
20 |
Correct |
3 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3460 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
3 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3224 KB |
Output is correct |
25 |
Correct |
3 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3420 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3164 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
3420 KB |
Output is correct |
31 |
Correct |
2 ms |
3420 KB |
Output is correct |
32 |
Correct |
2 ms |
3420 KB |
Output is correct |
33 |
Correct |
3 ms |
3420 KB |
Output is correct |
34 |
Correct |
13 ms |
7004 KB |
Output is correct |
35 |
Correct |
125 ms |
35276 KB |
Output is correct |
36 |
Correct |
131 ms |
35016 KB |
Output is correct |
37 |
Correct |
139 ms |
34032 KB |
Output is correct |
38 |
Correct |
123 ms |
32712 KB |
Output is correct |
39 |
Correct |
117 ms |
32220 KB |
Output is correct |
40 |
Correct |
102 ms |
29420 KB |
Output is correct |
41 |
Correct |
127 ms |
36272 KB |
Output is correct |
42 |
Correct |
127 ms |
36060 KB |
Output is correct |
43 |
Correct |
100 ms |
28496 KB |
Output is correct |
44 |
Correct |
117 ms |
33000 KB |
Output is correct |
45 |
Correct |
114 ms |
30860 KB |
Output is correct |
46 |
Correct |
115 ms |
34896 KB |
Output is correct |
47 |
Correct |
105 ms |
31476 KB |
Output is correct |
48 |
Correct |
110 ms |
29304 KB |
Output is correct |
49 |
Correct |
84 ms |
19536 KB |
Output is correct |
50 |
Correct |
66 ms |
17008 KB |
Output is correct |
51 |
Correct |
107 ms |
26556 KB |
Output is correct |
52 |
Correct |
174 ms |
40652 KB |
Output is correct |
53 |
Correct |
169 ms |
38456 KB |
Output is correct |
54 |
Correct |
209 ms |
46480 KB |
Output is correct |
55 |
Correct |
102 ms |
28364 KB |
Output is correct |
56 |
Correct |
190 ms |
36916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
97 ms |
29060 KB |
Output is correct |
10 |
Correct |
121 ms |
34540 KB |
Output is correct |
11 |
Correct |
112 ms |
33824 KB |
Output is correct |
12 |
Correct |
156 ms |
35920 KB |
Output is correct |
13 |
Correct |
92 ms |
28848 KB |
Output is correct |
14 |
Correct |
101 ms |
29156 KB |
Output is correct |
15 |
Correct |
187 ms |
39004 KB |
Output is correct |
16 |
Correct |
175 ms |
37828 KB |
Output is correct |
17 |
Correct |
188 ms |
40196 KB |
Output is correct |
18 |
Correct |
144 ms |
32712 KB |
Output is correct |
19 |
Correct |
130 ms |
30668 KB |
Output is correct |
20 |
Correct |
134 ms |
31776 KB |
Output is correct |
21 |
Correct |
117 ms |
31176 KB |
Output is correct |
22 |
Correct |
126 ms |
31732 KB |
Output is correct |
23 |
Correct |
165 ms |
31560 KB |
Output is correct |
24 |
Correct |
114 ms |
30416 KB |
Output is correct |
25 |
Correct |
129 ms |
31204 KB |
Output is correct |
26 |
Correct |
126 ms |
30156 KB |
Output is correct |
27 |
Correct |
2 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3452 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3420 KB |
Output is correct |
32 |
Correct |
3 ms |
3420 KB |
Output is correct |
33 |
Correct |
2 ms |
3460 KB |
Output is correct |
34 |
Correct |
2 ms |
3420 KB |
Output is correct |
35 |
Correct |
3 ms |
3420 KB |
Output is correct |
36 |
Correct |
13 ms |
7004 KB |
Output is correct |
37 |
Correct |
125 ms |
35276 KB |
Output is correct |
38 |
Correct |
131 ms |
35016 KB |
Output is correct |
39 |
Correct |
139 ms |
34032 KB |
Output is correct |
40 |
Correct |
123 ms |
32712 KB |
Output is correct |
41 |
Correct |
117 ms |
32220 KB |
Output is correct |
42 |
Correct |
102 ms |
29420 KB |
Output is correct |
43 |
Correct |
127 ms |
36272 KB |
Output is correct |
44 |
Correct |
127 ms |
36060 KB |
Output is correct |
45 |
Correct |
100 ms |
28496 KB |
Output is correct |
46 |
Correct |
117 ms |
33000 KB |
Output is correct |
47 |
Correct |
16 ms |
7000 KB |
Output is correct |
48 |
Correct |
208 ms |
39440 KB |
Output is correct |
49 |
Correct |
232 ms |
38408 KB |
Output is correct |
50 |
Correct |
224 ms |
38384 KB |
Output is correct |
51 |
Correct |
183 ms |
37324 KB |
Output is correct |
52 |
Correct |
172 ms |
34600 KB |
Output is correct |
53 |
Correct |
128 ms |
26432 KB |
Output is correct |
54 |
Correct |
219 ms |
39476 KB |
Output is correct |
55 |
Correct |
214 ms |
40300 KB |
Output is correct |
56 |
Correct |
158 ms |
32460 KB |
Output is correct |
57 |
Correct |
204 ms |
36296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3420 KB |
Output is correct |
10 |
Correct |
97 ms |
29060 KB |
Output is correct |
11 |
Correct |
121 ms |
34540 KB |
Output is correct |
12 |
Correct |
112 ms |
33824 KB |
Output is correct |
13 |
Correct |
156 ms |
35920 KB |
Output is correct |
14 |
Correct |
92 ms |
28848 KB |
Output is correct |
15 |
Correct |
101 ms |
29156 KB |
Output is correct |
16 |
Correct |
187 ms |
39004 KB |
Output is correct |
17 |
Correct |
175 ms |
37828 KB |
Output is correct |
18 |
Correct |
188 ms |
40196 KB |
Output is correct |
19 |
Correct |
144 ms |
32712 KB |
Output is correct |
20 |
Correct |
130 ms |
30668 KB |
Output is correct |
21 |
Correct |
134 ms |
31776 KB |
Output is correct |
22 |
Correct |
117 ms |
31176 KB |
Output is correct |
23 |
Correct |
126 ms |
31732 KB |
Output is correct |
24 |
Correct |
165 ms |
31560 KB |
Output is correct |
25 |
Correct |
114 ms |
30416 KB |
Output is correct |
26 |
Correct |
129 ms |
31204 KB |
Output is correct |
27 |
Correct |
126 ms |
30156 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3452 KB |
Output is correct |
30 |
Correct |
2 ms |
3420 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
3420 KB |
Output is correct |
33 |
Correct |
3 ms |
3420 KB |
Output is correct |
34 |
Correct |
2 ms |
3460 KB |
Output is correct |
35 |
Correct |
2 ms |
3420 KB |
Output is correct |
36 |
Correct |
3 ms |
3420 KB |
Output is correct |
37 |
Correct |
13 ms |
7004 KB |
Output is correct |
38 |
Correct |
125 ms |
35276 KB |
Output is correct |
39 |
Correct |
131 ms |
35016 KB |
Output is correct |
40 |
Correct |
139 ms |
34032 KB |
Output is correct |
41 |
Correct |
123 ms |
32712 KB |
Output is correct |
42 |
Correct |
117 ms |
32220 KB |
Output is correct |
43 |
Correct |
102 ms |
29420 KB |
Output is correct |
44 |
Correct |
127 ms |
36272 KB |
Output is correct |
45 |
Correct |
127 ms |
36060 KB |
Output is correct |
46 |
Correct |
100 ms |
28496 KB |
Output is correct |
47 |
Correct |
117 ms |
33000 KB |
Output is correct |
48 |
Correct |
16 ms |
7000 KB |
Output is correct |
49 |
Correct |
208 ms |
39440 KB |
Output is correct |
50 |
Correct |
232 ms |
38408 KB |
Output is correct |
51 |
Correct |
224 ms |
38384 KB |
Output is correct |
52 |
Correct |
183 ms |
37324 KB |
Output is correct |
53 |
Correct |
172 ms |
34600 KB |
Output is correct |
54 |
Correct |
128 ms |
26432 KB |
Output is correct |
55 |
Correct |
219 ms |
39476 KB |
Output is correct |
56 |
Correct |
214 ms |
40300 KB |
Output is correct |
57 |
Correct |
158 ms |
32460 KB |
Output is correct |
58 |
Correct |
204 ms |
36296 KB |
Output is correct |
59 |
Correct |
51 ms |
11876 KB |
Output is correct |
60 |
Correct |
181 ms |
38728 KB |
Output is correct |
61 |
Correct |
181 ms |
37836 KB |
Output is correct |
62 |
Correct |
180 ms |
40044 KB |
Output is correct |
63 |
Correct |
151 ms |
32840 KB |
Output is correct |
64 |
Correct |
2 ms |
3224 KB |
Output is correct |
65 |
Correct |
3 ms |
3420 KB |
Output is correct |
66 |
Correct |
2 ms |
3420 KB |
Output is correct |
67 |
Correct |
3 ms |
3420 KB |
Output is correct |
68 |
Correct |
2 ms |
3164 KB |
Output is correct |
69 |
Correct |
2 ms |
3420 KB |
Output is correct |
70 |
Correct |
2 ms |
3420 KB |
Output is correct |
71 |
Correct |
2 ms |
3420 KB |
Output is correct |
72 |
Correct |
2 ms |
3420 KB |
Output is correct |
73 |
Correct |
3 ms |
3420 KB |
Output is correct |
74 |
Correct |
114 ms |
30860 KB |
Output is correct |
75 |
Correct |
115 ms |
34896 KB |
Output is correct |
76 |
Correct |
105 ms |
31476 KB |
Output is correct |
77 |
Correct |
110 ms |
29304 KB |
Output is correct |
78 |
Correct |
84 ms |
19536 KB |
Output is correct |
79 |
Correct |
66 ms |
17008 KB |
Output is correct |
80 |
Correct |
107 ms |
26556 KB |
Output is correct |
81 |
Correct |
174 ms |
40652 KB |
Output is correct |
82 |
Correct |
169 ms |
38456 KB |
Output is correct |
83 |
Correct |
209 ms |
46480 KB |
Output is correct |
84 |
Correct |
102 ms |
28364 KB |
Output is correct |
85 |
Correct |
190 ms |
36916 KB |
Output is correct |
86 |
Correct |
54 ms |
14172 KB |
Output is correct |
87 |
Correct |
195 ms |
37660 KB |
Output is correct |
88 |
Correct |
172 ms |
37832 KB |
Output is correct |
89 |
Correct |
139 ms |
31828 KB |
Output is correct |
90 |
Correct |
141 ms |
24144 KB |
Output is correct |
91 |
Correct |
169 ms |
24148 KB |
Output is correct |
92 |
Correct |
145 ms |
29644 KB |
Output is correct |
93 |
Correct |
243 ms |
43548 KB |
Output is correct |
94 |
Correct |
218 ms |
42444 KB |
Output is correct |
95 |
Correct |
298 ms |
51096 KB |
Output is correct |
96 |
Correct |
179 ms |
32460 KB |
Output is correct |
97 |
Correct |
219 ms |
37044 KB |
Output is correct |