#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
vector<pair<int, ii> > edges;
int n, m;
vi p(100001), sz(100001, 1), s(100001), e(100001), line(100001, -1), sub(100001);
vi d(100001), g[100001];
int get(int a){
if (p[a] == a) return a;
return get(p[a]);
}
void Union(int a, int b, int w){
int c = get(a); int d = get(b);
if (c == d){
if (line[c] == -1) line[c] = w;
return;
}
if (sz[c] < sz[d]){
swap(c, d); swap(a, b);
}
p[d] = c;
sz[c] += sz[d];
sub[d] = w;
if (line[c] == -1 && line[d] == -1){
if (s[c] == a && b == s[d]){
s[c] = e[d]; return;
}
if (s[c] == a && b == e[d]){
s[c] = s[d]; return;
}
if (e[c] == a && b == s[d]){
e[c] = e[d]; return;
}
if (e[c] == a && b == e[d]){
e[c] = s[d]; return;
}
line[c] = w; return;
}
if (line[c] == -1) line[c] = w;
}
void init(int N, int M, vi U, vi V, vi W) {
n = N; m = M;
FOR(i, 0, m){
edges.pb({W[i], {U[i], V[i]}});
}
FOR(i, 0, n){
p[i] = i;
s[i] = i;
e[i] = i;
}
sort(edges.begin(), edges.end());
FOR(i, 0, m){
Union(edges[i].S.F, edges[i].S.S, edges[i].F);
}
int head;
FOR(i, 0, n){
if (p[i] != i){
g[p[i]].pb(i); continue;
}
head = i;
}
vi bfs; bfs.pb(head);
FOR(i, 0, bfs.size()){
int u = bfs[i];
for (int v : g[u]){
d[v] = d[u] + 1;
bfs.pb(v);
}
}
}
int getMinimumFuelCapacity(int x, int y) {
int l = 0, r = 1000000001;
while (r-l > 1){
int u = x; int v = y;
int m = (l+r)/2;
while(sub[u] <= m && u != p[u]){
u = p[u];
}
while(sub[v] <= m && v != p[v]){
v = p[v];
}
if (u == v && line[u] <= m && line[u] != -1){
r = m;
}else{
l = m;
}
}
if (r == 1000000001) return -1;
else return r;
return -1;
}
Compilation message
swap.cpp: In function 'void init(int, int, vi, vi, vi)':
swap.cpp:8:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
77 | FOR(i, 0, bfs.size()){
| ~~~~~~~~~~~~~~~~
swap.cpp:77:5: note: in expansion of macro 'FOR'
77 | FOR(i, 0, bfs.size()){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5376 KB |
Output is correct |
2 |
Correct |
3 ms |
5384 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5420 KB |
Output is correct |
6 |
Correct |
4 ms |
5452 KB |
Output is correct |
7 |
Correct |
4 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5452 KB |
Output is correct |
9 |
Correct |
54 ms |
11576 KB |
Output is correct |
10 |
Correct |
63 ms |
12768 KB |
Output is correct |
11 |
Correct |
68 ms |
12756 KB |
Output is correct |
12 |
Correct |
66 ms |
13060 KB |
Output is correct |
13 |
Correct |
56 ms |
12416 KB |
Output is correct |
14 |
Correct |
74 ms |
11912 KB |
Output is correct |
15 |
Correct |
296 ms |
16748 KB |
Output is correct |
16 |
Correct |
295 ms |
16564 KB |
Output is correct |
17 |
Correct |
299 ms |
16912 KB |
Output is correct |
18 |
Correct |
180 ms |
16396 KB |
Output is correct |
19 |
Correct |
181 ms |
11604 KB |
Output is correct |
20 |
Correct |
293 ms |
17204 KB |
Output is correct |
21 |
Correct |
309 ms |
17484 KB |
Output is correct |
22 |
Correct |
318 ms |
17768 KB |
Output is correct |
23 |
Correct |
194 ms |
17268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5376 KB |
Output is correct |
2 |
Correct |
3 ms |
5384 KB |
Output is correct |
3 |
Correct |
187 ms |
16372 KB |
Output is correct |
4 |
Correct |
182 ms |
16500 KB |
Output is correct |
5 |
Correct |
196 ms |
17124 KB |
Output is correct |
6 |
Correct |
179 ms |
16372 KB |
Output is correct |
7 |
Correct |
186 ms |
16672 KB |
Output is correct |
8 |
Correct |
185 ms |
16488 KB |
Output is correct |
9 |
Correct |
181 ms |
16568 KB |
Output is correct |
10 |
Correct |
188 ms |
16504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5376 KB |
Output is correct |
2 |
Correct |
3 ms |
5384 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5420 KB |
Output is correct |
6 |
Correct |
4 ms |
5452 KB |
Output is correct |
7 |
Correct |
4 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5452 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
4 ms |
5452 KB |
Output is correct |
11 |
Correct |
4 ms |
5408 KB |
Output is correct |
12 |
Correct |
4 ms |
5452 KB |
Output is correct |
13 |
Correct |
4 ms |
5452 KB |
Output is correct |
14 |
Correct |
4 ms |
5452 KB |
Output is correct |
15 |
Correct |
4 ms |
5452 KB |
Output is correct |
16 |
Correct |
4 ms |
5452 KB |
Output is correct |
17 |
Correct |
4 ms |
5452 KB |
Output is correct |
18 |
Correct |
4 ms |
5452 KB |
Output is correct |
19 |
Correct |
4 ms |
5452 KB |
Output is correct |
20 |
Correct |
4 ms |
5452 KB |
Output is correct |
21 |
Correct |
4 ms |
5416 KB |
Output is correct |
22 |
Correct |
4 ms |
5420 KB |
Output is correct |
23 |
Correct |
4 ms |
5452 KB |
Output is correct |
24 |
Correct |
5 ms |
5412 KB |
Output is correct |
25 |
Correct |
4 ms |
5452 KB |
Output is correct |
26 |
Correct |
5 ms |
5452 KB |
Output is correct |
27 |
Correct |
4 ms |
5452 KB |
Output is correct |
28 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5376 KB |
Output is correct |
3 |
Correct |
3 ms |
5384 KB |
Output is correct |
4 |
Correct |
3 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5324 KB |
Output is correct |
6 |
Correct |
4 ms |
5420 KB |
Output is correct |
7 |
Correct |
4 ms |
5452 KB |
Output is correct |
8 |
Correct |
4 ms |
5428 KB |
Output is correct |
9 |
Correct |
4 ms |
5452 KB |
Output is correct |
10 |
Correct |
54 ms |
11576 KB |
Output is correct |
11 |
Correct |
63 ms |
12768 KB |
Output is correct |
12 |
Correct |
68 ms |
12756 KB |
Output is correct |
13 |
Correct |
66 ms |
13060 KB |
Output is correct |
14 |
Correct |
56 ms |
12416 KB |
Output is correct |
15 |
Correct |
4 ms |
5452 KB |
Output is correct |
16 |
Correct |
4 ms |
5408 KB |
Output is correct |
17 |
Correct |
4 ms |
5452 KB |
Output is correct |
18 |
Correct |
4 ms |
5452 KB |
Output is correct |
19 |
Correct |
4 ms |
5452 KB |
Output is correct |
20 |
Correct |
4 ms |
5452 KB |
Output is correct |
21 |
Correct |
4 ms |
5452 KB |
Output is correct |
22 |
Correct |
4 ms |
5452 KB |
Output is correct |
23 |
Correct |
4 ms |
5452 KB |
Output is correct |
24 |
Correct |
4 ms |
5452 KB |
Output is correct |
25 |
Correct |
4 ms |
5452 KB |
Output is correct |
26 |
Correct |
4 ms |
5416 KB |
Output is correct |
27 |
Correct |
4 ms |
5420 KB |
Output is correct |
28 |
Correct |
4 ms |
5452 KB |
Output is correct |
29 |
Correct |
5 ms |
5412 KB |
Output is correct |
30 |
Correct |
4 ms |
5452 KB |
Output is correct |
31 |
Correct |
5 ms |
5452 KB |
Output is correct |
32 |
Correct |
4 ms |
5452 KB |
Output is correct |
33 |
Correct |
4 ms |
5452 KB |
Output is correct |
34 |
Correct |
11 ms |
6408 KB |
Output is correct |
35 |
Correct |
65 ms |
12804 KB |
Output is correct |
36 |
Correct |
68 ms |
12852 KB |
Output is correct |
37 |
Correct |
67 ms |
12856 KB |
Output is correct |
38 |
Correct |
64 ms |
12652 KB |
Output is correct |
39 |
Correct |
66 ms |
12648 KB |
Output is correct |
40 |
Correct |
61 ms |
12116 KB |
Output is correct |
41 |
Correct |
73 ms |
13072 KB |
Output is correct |
42 |
Correct |
70 ms |
12784 KB |
Output is correct |
43 |
Correct |
60 ms |
12160 KB |
Output is correct |
44 |
Correct |
70 ms |
13072 KB |
Output is correct |
45 |
Correct |
91 ms |
15284 KB |
Output is correct |
46 |
Correct |
88 ms |
12856 KB |
Output is correct |
47 |
Correct |
65 ms |
12812 KB |
Output is correct |
48 |
Correct |
85 ms |
13336 KB |
Output is correct |
49 |
Correct |
79 ms |
15024 KB |
Output is correct |
50 |
Correct |
61 ms |
12152 KB |
Output is correct |
51 |
Correct |
73 ms |
13792 KB |
Output is correct |
52 |
Correct |
99 ms |
16564 KB |
Output is correct |
53 |
Correct |
112 ms |
17532 KB |
Output is correct |
54 |
Correct |
134 ms |
18464 KB |
Output is correct |
55 |
Correct |
54 ms |
12088 KB |
Output is correct |
56 |
Correct |
100 ms |
16972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5376 KB |
Output is correct |
2 |
Correct |
3 ms |
5384 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5420 KB |
Output is correct |
6 |
Correct |
4 ms |
5452 KB |
Output is correct |
7 |
Correct |
4 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5452 KB |
Output is correct |
9 |
Correct |
54 ms |
11576 KB |
Output is correct |
10 |
Correct |
63 ms |
12768 KB |
Output is correct |
11 |
Correct |
68 ms |
12756 KB |
Output is correct |
12 |
Correct |
66 ms |
13060 KB |
Output is correct |
13 |
Correct |
56 ms |
12416 KB |
Output is correct |
14 |
Correct |
74 ms |
11912 KB |
Output is correct |
15 |
Correct |
296 ms |
16748 KB |
Output is correct |
16 |
Correct |
295 ms |
16564 KB |
Output is correct |
17 |
Correct |
299 ms |
16912 KB |
Output is correct |
18 |
Correct |
180 ms |
16396 KB |
Output is correct |
19 |
Correct |
187 ms |
16372 KB |
Output is correct |
20 |
Correct |
182 ms |
16500 KB |
Output is correct |
21 |
Correct |
196 ms |
17124 KB |
Output is correct |
22 |
Correct |
179 ms |
16372 KB |
Output is correct |
23 |
Correct |
186 ms |
16672 KB |
Output is correct |
24 |
Correct |
185 ms |
16488 KB |
Output is correct |
25 |
Correct |
181 ms |
16568 KB |
Output is correct |
26 |
Correct |
188 ms |
16504 KB |
Output is correct |
27 |
Correct |
4 ms |
5452 KB |
Output is correct |
28 |
Correct |
4 ms |
5408 KB |
Output is correct |
29 |
Correct |
4 ms |
5452 KB |
Output is correct |
30 |
Correct |
4 ms |
5452 KB |
Output is correct |
31 |
Correct |
4 ms |
5452 KB |
Output is correct |
32 |
Correct |
4 ms |
5452 KB |
Output is correct |
33 |
Correct |
4 ms |
5452 KB |
Output is correct |
34 |
Correct |
4 ms |
5452 KB |
Output is correct |
35 |
Correct |
4 ms |
5452 KB |
Output is correct |
36 |
Correct |
11 ms |
6408 KB |
Output is correct |
37 |
Correct |
65 ms |
12804 KB |
Output is correct |
38 |
Correct |
68 ms |
12852 KB |
Output is correct |
39 |
Correct |
67 ms |
12856 KB |
Output is correct |
40 |
Correct |
64 ms |
12652 KB |
Output is correct |
41 |
Correct |
66 ms |
12648 KB |
Output is correct |
42 |
Correct |
61 ms |
12116 KB |
Output is correct |
43 |
Correct |
73 ms |
13072 KB |
Output is correct |
44 |
Correct |
70 ms |
12784 KB |
Output is correct |
45 |
Correct |
60 ms |
12160 KB |
Output is correct |
46 |
Correct |
70 ms |
13072 KB |
Output is correct |
47 |
Correct |
31 ms |
6876 KB |
Output is correct |
48 |
Correct |
319 ms |
16876 KB |
Output is correct |
49 |
Correct |
307 ms |
16928 KB |
Output is correct |
50 |
Correct |
309 ms |
16960 KB |
Output is correct |
51 |
Correct |
299 ms |
16800 KB |
Output is correct |
52 |
Correct |
288 ms |
16448 KB |
Output is correct |
53 |
Correct |
258 ms |
15660 KB |
Output is correct |
54 |
Correct |
335 ms |
17792 KB |
Output is correct |
55 |
Correct |
339 ms |
16912 KB |
Output is correct |
56 |
Correct |
198 ms |
16356 KB |
Output is correct |
57 |
Correct |
288 ms |
17768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5376 KB |
Output is correct |
3 |
Correct |
3 ms |
5384 KB |
Output is correct |
4 |
Correct |
3 ms |
5324 KB |
Output is correct |
5 |
Correct |
4 ms |
5324 KB |
Output is correct |
6 |
Correct |
4 ms |
5420 KB |
Output is correct |
7 |
Correct |
4 ms |
5452 KB |
Output is correct |
8 |
Correct |
4 ms |
5428 KB |
Output is correct |
9 |
Correct |
4 ms |
5452 KB |
Output is correct |
10 |
Correct |
54 ms |
11576 KB |
Output is correct |
11 |
Correct |
63 ms |
12768 KB |
Output is correct |
12 |
Correct |
68 ms |
12756 KB |
Output is correct |
13 |
Correct |
66 ms |
13060 KB |
Output is correct |
14 |
Correct |
56 ms |
12416 KB |
Output is correct |
15 |
Correct |
74 ms |
11912 KB |
Output is correct |
16 |
Correct |
296 ms |
16748 KB |
Output is correct |
17 |
Correct |
295 ms |
16564 KB |
Output is correct |
18 |
Correct |
299 ms |
16912 KB |
Output is correct |
19 |
Correct |
180 ms |
16396 KB |
Output is correct |
20 |
Correct |
187 ms |
16372 KB |
Output is correct |
21 |
Correct |
182 ms |
16500 KB |
Output is correct |
22 |
Correct |
196 ms |
17124 KB |
Output is correct |
23 |
Correct |
179 ms |
16372 KB |
Output is correct |
24 |
Correct |
186 ms |
16672 KB |
Output is correct |
25 |
Correct |
185 ms |
16488 KB |
Output is correct |
26 |
Correct |
181 ms |
16568 KB |
Output is correct |
27 |
Correct |
188 ms |
16504 KB |
Output is correct |
28 |
Correct |
4 ms |
5452 KB |
Output is correct |
29 |
Correct |
4 ms |
5408 KB |
Output is correct |
30 |
Correct |
4 ms |
5452 KB |
Output is correct |
31 |
Correct |
4 ms |
5452 KB |
Output is correct |
32 |
Correct |
4 ms |
5452 KB |
Output is correct |
33 |
Correct |
4 ms |
5452 KB |
Output is correct |
34 |
Correct |
4 ms |
5452 KB |
Output is correct |
35 |
Correct |
4 ms |
5452 KB |
Output is correct |
36 |
Correct |
4 ms |
5452 KB |
Output is correct |
37 |
Correct |
11 ms |
6408 KB |
Output is correct |
38 |
Correct |
65 ms |
12804 KB |
Output is correct |
39 |
Correct |
68 ms |
12852 KB |
Output is correct |
40 |
Correct |
67 ms |
12856 KB |
Output is correct |
41 |
Correct |
64 ms |
12652 KB |
Output is correct |
42 |
Correct |
66 ms |
12648 KB |
Output is correct |
43 |
Correct |
61 ms |
12116 KB |
Output is correct |
44 |
Correct |
73 ms |
13072 KB |
Output is correct |
45 |
Correct |
70 ms |
12784 KB |
Output is correct |
46 |
Correct |
60 ms |
12160 KB |
Output is correct |
47 |
Correct |
70 ms |
13072 KB |
Output is correct |
48 |
Correct |
31 ms |
6876 KB |
Output is correct |
49 |
Correct |
319 ms |
16876 KB |
Output is correct |
50 |
Correct |
307 ms |
16928 KB |
Output is correct |
51 |
Correct |
309 ms |
16960 KB |
Output is correct |
52 |
Correct |
299 ms |
16800 KB |
Output is correct |
53 |
Correct |
288 ms |
16448 KB |
Output is correct |
54 |
Correct |
258 ms |
15660 KB |
Output is correct |
55 |
Correct |
335 ms |
17792 KB |
Output is correct |
56 |
Correct |
339 ms |
16912 KB |
Output is correct |
57 |
Correct |
198 ms |
16356 KB |
Output is correct |
58 |
Correct |
288 ms |
17768 KB |
Output is correct |
59 |
Correct |
181 ms |
11604 KB |
Output is correct |
60 |
Correct |
293 ms |
17204 KB |
Output is correct |
61 |
Correct |
309 ms |
17484 KB |
Output is correct |
62 |
Correct |
318 ms |
17768 KB |
Output is correct |
63 |
Correct |
194 ms |
17268 KB |
Output is correct |
64 |
Correct |
4 ms |
5452 KB |
Output is correct |
65 |
Correct |
4 ms |
5452 KB |
Output is correct |
66 |
Correct |
4 ms |
5416 KB |
Output is correct |
67 |
Correct |
4 ms |
5420 KB |
Output is correct |
68 |
Correct |
4 ms |
5452 KB |
Output is correct |
69 |
Correct |
5 ms |
5412 KB |
Output is correct |
70 |
Correct |
4 ms |
5452 KB |
Output is correct |
71 |
Correct |
5 ms |
5452 KB |
Output is correct |
72 |
Correct |
4 ms |
5452 KB |
Output is correct |
73 |
Correct |
4 ms |
5452 KB |
Output is correct |
74 |
Correct |
91 ms |
15284 KB |
Output is correct |
75 |
Correct |
88 ms |
12856 KB |
Output is correct |
76 |
Correct |
65 ms |
12812 KB |
Output is correct |
77 |
Correct |
85 ms |
13336 KB |
Output is correct |
78 |
Correct |
79 ms |
15024 KB |
Output is correct |
79 |
Correct |
61 ms |
12152 KB |
Output is correct |
80 |
Correct |
73 ms |
13792 KB |
Output is correct |
81 |
Correct |
99 ms |
16564 KB |
Output is correct |
82 |
Correct |
112 ms |
17532 KB |
Output is correct |
83 |
Correct |
134 ms |
18464 KB |
Output is correct |
84 |
Correct |
54 ms |
12088 KB |
Output is correct |
85 |
Correct |
100 ms |
16972 KB |
Output is correct |
86 |
Correct |
74 ms |
9660 KB |
Output is correct |
87 |
Correct |
301 ms |
16904 KB |
Output is correct |
88 |
Correct |
307 ms |
16828 KB |
Output is correct |
89 |
Correct |
229 ms |
16872 KB |
Output is correct |
90 |
Correct |
241 ms |
18744 KB |
Output is correct |
91 |
Correct |
245 ms |
18412 KB |
Output is correct |
92 |
Correct |
246 ms |
18556 KB |
Output is correct |
93 |
Correct |
337 ms |
20484 KB |
Output is correct |
94 |
Correct |
292 ms |
21300 KB |
Output is correct |
95 |
Correct |
391 ms |
22348 KB |
Output is correct |
96 |
Correct |
198 ms |
16488 KB |
Output is correct |
97 |
Correct |
261 ms |
19204 KB |
Output is correct |