#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+50;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
struct UF {
vector<int> A;
vector<vector<pii>> P, B, C;
vector<vector<int>> elements;
int get(int t, vector<pii> &T) {
auto iter = upper_bound(T.begin(), T.end(), pii(t, INF));
return (--iter)->se;
}
int fin(int t, int x) {
return get(t, P[x]);
}
int max_deg(int t, int x) {
return get(t, B[fin(t, x)]);
}
int has_cyc(int t, int x) {
return get(t, C[fin(t, x)]);
}
void mer(int t, int x, int y) {
int xx = P[x].back().se, yy = P[y].back().se;
if(xx != yy) {
if(elements[xx].size() < elements[yy].size()) swap(xx, yy), swap(x, y);
B[xx].push_back({t, max(max(B[xx].back().se, B[yy].back().se), max(++A[x], ++A[y]))});
C[xx].push_back({t, C[xx].back().se || C[yy].back().se});
for(auto i : elements[yy]) {
P[i].push_back({t, xx});
elements[xx].push_back(i);
}
elements[yy].clear();
} else {
B[xx].push_back({t, max(B[xx].back().se, max(++A[x], ++A[y]))});
C[xx].push_back({t, 1});
}
}
UF(int n) {
A.resize(n, 0), B.resize(n, {{0, 0}}), C.resize(n, {{0, 0}});
elements.resize(n), P.resize(n);
for(int i = 0; i < n; i++) {
elements[i].push_back(i);
P[i].push_back({0, i});
}
}
};
int n, m;
vector<piii> E;
UF uf(0);
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
uf = UF(N), n = N, m = M, E.resize(M);
for(int i = 0; i < M; i++) E[i] = {W[i], {U[i], V[i]}};
sort(E.begin(), E.end());
for(auto &i : E) uf.mer(i.fi, i.se.fi, i.se.se);
}
int getMinimumFuelCapacity(int X, int Y) {
int s = 0, e = INF-5;
while(s+1 < e) {
int mi = s+e>>1;
//cout << s << " " << e << " " << mi << " " << X << " " << Y << " " << mi-1 << "\n";
if(uf.fin(mi-1, X) == uf.fin(mi-1, Y) && (uf.max_deg(mi-1, X) >= 3 || uf.has_cyc(mi-1, X))) e = mi;
else s = mi;
}
if(s == INF-6) return -1;
else return s;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:82:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
82 | int mi = s+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
164 ms |
31044 KB |
Output is correct |
10 |
Correct |
211 ms |
37776 KB |
Output is correct |
11 |
Correct |
204 ms |
36928 KB |
Output is correct |
12 |
Correct |
219 ms |
39328 KB |
Output is correct |
13 |
Correct |
119 ms |
30616 KB |
Output is correct |
14 |
Correct |
186 ms |
31128 KB |
Output is correct |
15 |
Correct |
462 ms |
40136 KB |
Output is correct |
16 |
Correct |
470 ms |
38808 KB |
Output is correct |
17 |
Correct |
480 ms |
41272 KB |
Output is correct |
18 |
Correct |
508 ms |
32516 KB |
Output is correct |
19 |
Correct |
232 ms |
9728 KB |
Output is correct |
20 |
Correct |
461 ms |
41308 KB |
Output is correct |
21 |
Correct |
477 ms |
39964 KB |
Output is correct |
22 |
Correct |
505 ms |
42592 KB |
Output is correct |
23 |
Correct |
546 ms |
33804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
436 ms |
30052 KB |
Output is correct |
4 |
Correct |
408 ms |
31380 KB |
Output is correct |
5 |
Correct |
425 ms |
30676 KB |
Output is correct |
6 |
Correct |
411 ms |
31232 KB |
Output is correct |
7 |
Correct |
433 ms |
31068 KB |
Output is correct |
8 |
Correct |
420 ms |
29860 KB |
Output is correct |
9 |
Correct |
421 ms |
30884 KB |
Output is correct |
10 |
Correct |
419 ms |
29688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
568 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
440 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
164 ms |
31044 KB |
Output is correct |
11 |
Correct |
211 ms |
37776 KB |
Output is correct |
12 |
Correct |
204 ms |
36928 KB |
Output is correct |
13 |
Correct |
219 ms |
39328 KB |
Output is correct |
14 |
Correct |
119 ms |
30616 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
720 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
568 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
440 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
724 KB |
Output is correct |
34 |
Correct |
18 ms |
5432 KB |
Output is correct |
35 |
Correct |
238 ms |
40852 KB |
Output is correct |
36 |
Correct |
222 ms |
40644 KB |
Output is correct |
37 |
Correct |
229 ms |
40172 KB |
Output is correct |
38 |
Correct |
210 ms |
39056 KB |
Output is correct |
39 |
Correct |
207 ms |
38628 KB |
Output is correct |
40 |
Correct |
171 ms |
34792 KB |
Output is correct |
41 |
Correct |
224 ms |
41700 KB |
Output is correct |
42 |
Correct |
222 ms |
41540 KB |
Output is correct |
43 |
Correct |
120 ms |
31632 KB |
Output is correct |
44 |
Correct |
192 ms |
38940 KB |
Output is correct |
45 |
Correct |
166 ms |
31808 KB |
Output is correct |
46 |
Correct |
240 ms |
40704 KB |
Output is correct |
47 |
Correct |
198 ms |
36944 KB |
Output is correct |
48 |
Correct |
155 ms |
34224 KB |
Output is correct |
49 |
Correct |
60 ms |
12160 KB |
Output is correct |
50 |
Correct |
50 ms |
10828 KB |
Output is correct |
51 |
Correct |
120 ms |
26752 KB |
Output is correct |
52 |
Correct |
248 ms |
44928 KB |
Output is correct |
53 |
Correct |
223 ms |
41688 KB |
Output is correct |
54 |
Correct |
275 ms |
49476 KB |
Output is correct |
55 |
Correct |
110 ms |
31836 KB |
Output is correct |
56 |
Correct |
219 ms |
39740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
164 ms |
31044 KB |
Output is correct |
10 |
Correct |
211 ms |
37776 KB |
Output is correct |
11 |
Correct |
204 ms |
36928 KB |
Output is correct |
12 |
Correct |
219 ms |
39328 KB |
Output is correct |
13 |
Correct |
119 ms |
30616 KB |
Output is correct |
14 |
Correct |
186 ms |
31128 KB |
Output is correct |
15 |
Correct |
462 ms |
40136 KB |
Output is correct |
16 |
Correct |
470 ms |
38808 KB |
Output is correct |
17 |
Correct |
480 ms |
41272 KB |
Output is correct |
18 |
Correct |
508 ms |
32516 KB |
Output is correct |
19 |
Correct |
436 ms |
30052 KB |
Output is correct |
20 |
Correct |
408 ms |
31380 KB |
Output is correct |
21 |
Correct |
425 ms |
30676 KB |
Output is correct |
22 |
Correct |
411 ms |
31232 KB |
Output is correct |
23 |
Correct |
433 ms |
31068 KB |
Output is correct |
24 |
Correct |
420 ms |
29860 KB |
Output is correct |
25 |
Correct |
421 ms |
30884 KB |
Output is correct |
26 |
Correct |
419 ms |
29688 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
720 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
18 ms |
5432 KB |
Output is correct |
37 |
Correct |
238 ms |
40852 KB |
Output is correct |
38 |
Correct |
222 ms |
40644 KB |
Output is correct |
39 |
Correct |
229 ms |
40172 KB |
Output is correct |
40 |
Correct |
210 ms |
39056 KB |
Output is correct |
41 |
Correct |
207 ms |
38628 KB |
Output is correct |
42 |
Correct |
171 ms |
34792 KB |
Output is correct |
43 |
Correct |
224 ms |
41700 KB |
Output is correct |
44 |
Correct |
222 ms |
41540 KB |
Output is correct |
45 |
Correct |
120 ms |
31632 KB |
Output is correct |
46 |
Correct |
192 ms |
38940 KB |
Output is correct |
47 |
Correct |
35 ms |
5536 KB |
Output is correct |
48 |
Correct |
476 ms |
45972 KB |
Output is correct |
49 |
Correct |
457 ms |
45324 KB |
Output is correct |
50 |
Correct |
456 ms |
45100 KB |
Output is correct |
51 |
Correct |
444 ms |
44380 KB |
Output is correct |
52 |
Correct |
428 ms |
41544 KB |
Output is correct |
53 |
Correct |
362 ms |
31360 KB |
Output is correct |
54 |
Correct |
474 ms |
46644 KB |
Output is correct |
55 |
Correct |
453 ms |
46640 KB |
Output is correct |
56 |
Correct |
408 ms |
37224 KB |
Output is correct |
57 |
Correct |
453 ms |
44024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
164 ms |
31044 KB |
Output is correct |
11 |
Correct |
211 ms |
37776 KB |
Output is correct |
12 |
Correct |
204 ms |
36928 KB |
Output is correct |
13 |
Correct |
219 ms |
39328 KB |
Output is correct |
14 |
Correct |
119 ms |
30616 KB |
Output is correct |
15 |
Correct |
186 ms |
31128 KB |
Output is correct |
16 |
Correct |
462 ms |
40136 KB |
Output is correct |
17 |
Correct |
470 ms |
38808 KB |
Output is correct |
18 |
Correct |
480 ms |
41272 KB |
Output is correct |
19 |
Correct |
508 ms |
32516 KB |
Output is correct |
20 |
Correct |
436 ms |
30052 KB |
Output is correct |
21 |
Correct |
408 ms |
31380 KB |
Output is correct |
22 |
Correct |
425 ms |
30676 KB |
Output is correct |
23 |
Correct |
411 ms |
31232 KB |
Output is correct |
24 |
Correct |
433 ms |
31068 KB |
Output is correct |
25 |
Correct |
420 ms |
29860 KB |
Output is correct |
26 |
Correct |
421 ms |
30884 KB |
Output is correct |
27 |
Correct |
419 ms |
29688 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
720 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
18 ms |
5432 KB |
Output is correct |
38 |
Correct |
238 ms |
40852 KB |
Output is correct |
39 |
Correct |
222 ms |
40644 KB |
Output is correct |
40 |
Correct |
229 ms |
40172 KB |
Output is correct |
41 |
Correct |
210 ms |
39056 KB |
Output is correct |
42 |
Correct |
207 ms |
38628 KB |
Output is correct |
43 |
Correct |
171 ms |
34792 KB |
Output is correct |
44 |
Correct |
224 ms |
41700 KB |
Output is correct |
45 |
Correct |
222 ms |
41540 KB |
Output is correct |
46 |
Correct |
120 ms |
31632 KB |
Output is correct |
47 |
Correct |
192 ms |
38940 KB |
Output is correct |
48 |
Correct |
35 ms |
5536 KB |
Output is correct |
49 |
Correct |
476 ms |
45972 KB |
Output is correct |
50 |
Correct |
457 ms |
45324 KB |
Output is correct |
51 |
Correct |
456 ms |
45100 KB |
Output is correct |
52 |
Correct |
444 ms |
44380 KB |
Output is correct |
53 |
Correct |
428 ms |
41544 KB |
Output is correct |
54 |
Correct |
362 ms |
31360 KB |
Output is correct |
55 |
Correct |
474 ms |
46644 KB |
Output is correct |
56 |
Correct |
453 ms |
46640 KB |
Output is correct |
57 |
Correct |
408 ms |
37224 KB |
Output is correct |
58 |
Correct |
453 ms |
44024 KB |
Output is correct |
59 |
Correct |
232 ms |
9728 KB |
Output is correct |
60 |
Correct |
461 ms |
41308 KB |
Output is correct |
61 |
Correct |
477 ms |
39964 KB |
Output is correct |
62 |
Correct |
505 ms |
42592 KB |
Output is correct |
63 |
Correct |
546 ms |
33804 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
568 KB |
Output is correct |
66 |
Correct |
1 ms |
596 KB |
Output is correct |
67 |
Correct |
1 ms |
440 KB |
Output is correct |
68 |
Correct |
1 ms |
468 KB |
Output is correct |
69 |
Correct |
2 ms |
724 KB |
Output is correct |
70 |
Correct |
2 ms |
724 KB |
Output is correct |
71 |
Correct |
2 ms |
724 KB |
Output is correct |
72 |
Correct |
1 ms |
596 KB |
Output is correct |
73 |
Correct |
2 ms |
724 KB |
Output is correct |
74 |
Correct |
166 ms |
31808 KB |
Output is correct |
75 |
Correct |
240 ms |
40704 KB |
Output is correct |
76 |
Correct |
198 ms |
36944 KB |
Output is correct |
77 |
Correct |
155 ms |
34224 KB |
Output is correct |
78 |
Correct |
60 ms |
12160 KB |
Output is correct |
79 |
Correct |
50 ms |
10828 KB |
Output is correct |
80 |
Correct |
120 ms |
26752 KB |
Output is correct |
81 |
Correct |
248 ms |
44928 KB |
Output is correct |
82 |
Correct |
223 ms |
41688 KB |
Output is correct |
83 |
Correct |
275 ms |
49476 KB |
Output is correct |
84 |
Correct |
110 ms |
31836 KB |
Output is correct |
85 |
Correct |
219 ms |
39740 KB |
Output is correct |
86 |
Correct |
126 ms |
13232 KB |
Output is correct |
87 |
Correct |
461 ms |
44824 KB |
Output is correct |
88 |
Correct |
472 ms |
44936 KB |
Output is correct |
89 |
Correct |
480 ms |
36628 KB |
Output is correct |
90 |
Correct |
371 ms |
16184 KB |
Output is correct |
91 |
Correct |
375 ms |
18360 KB |
Output is correct |
92 |
Correct |
459 ms |
31384 KB |
Output is correct |
93 |
Correct |
570 ms |
48856 KB |
Output is correct |
94 |
Correct |
589 ms |
46324 KB |
Output is correct |
95 |
Correct |
626 ms |
53372 KB |
Output is correct |
96 |
Correct |
410 ms |
37080 KB |
Output is correct |
97 |
Correct |
533 ms |
42604 KB |
Output is correct |