// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int ALPH = 26;
const int LGN = 20;
constexpr int MOD = 1e9+7;
struct Node {
bool isl;
array<int,2> e;
int p;
int sz;
int ver;
Node() {}
};
struct DSU {
vector<Node> dt;
int cnt = 0;
void reset(int s) {
dt.resize(s + 3);
}
void make_set(int x) {
dt[x].p = x;
dt[x].isl = 1;
dt[x].e = {x, x};
dt[x].sz = 1;
dt[x].ver = cnt++;
}
int find_set(int x) {
return (x == dt[x].p) ? x : dt[x].p = find_set(dt[x].p);
}
int union_set(int x, int y) { // 0 nothing, 1 turned into non line, 2 merged as line, 3 merged and non line
int a = x, b = y;
x = find_set(x); y = find_set(y);
dt[x].ver = dt[y].ver = cnt++;
if(x == y) {
dt[x].isl = 0;
return 1;
}
if(dt[x].sz < dt[y].sz) {
swap(a, b);
swap(x, y);
}
dt[x].sz += dt[y].sz;
dt[y].p = x;
if(dt[x].isl && dt[y].isl && (dt[x].e[0] == a || dt[x].e[1] == a) && (dt[y].e[0] == b || dt[y].e[1] == b)) {
int en = dt[y].e[0];
if(dt[y].e[0] == b) en = dt[y].e[1];
if(dt[x].e[0] == a) dt[x].e[0] = en;
else dt[x].e[1] = en;
return 2;
}
else {
dt[x].isl = 0;
return 3;
}
}
};
int n,m,s;
vector<array<int,3> > edges;
vector<vector<int> > anc;
vector<int> cst;
vector<bool> stat;
void prec() {
for(int k = 1; k < LGN; k++) {
for(int i = 0; i < s; i++) {
anc[i][k] = anc[anc[i][k - 1]][k - 1];
}
}
}
bool check(int val, int x, int y) {
for(int k = LGN - 1; k >= 0; k--) {
if(cst[anc[x][k]] <= val) {
x = anc[x][k];
}
if(cst[anc[y][k]] <= val) {
y = anc[y][k];
}
}
// cout << x << " " << y << " xy" << endl;
if(x != y) return 0;
if(!stat[x]) return 0;
return 1;
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N; m = M; s = N + M;
edges.resize(M);
REP(i,M) {
edges[i] = {W[i], U[i], V[i]};
}
sort(all(edges));
anc.assign(s, vector<int>(LGN, s - 1));
cst.assign(s, 0);
stat.assign(s, 0);
DSU ds;
ds.reset(n);
REP(i,n) {
stat[i] = 0;
ds.make_set(i);
}
for(auto &c : edges) {
anc[ds.dt[ds.find_set(c[1])].ver][0] = ds.cnt;
anc[ds.dt[ds.find_set(c[2])].ver][0] = ds.cnt;
int ret = ds.union_set(c[1], c[2]);
if(ret & 1) {
stat[ds.cnt - 1] = 1;
}
cst[ds.cnt - 1] = c[0];
}
// for(int i = 0; i < s ; i++) {
// cout << "i:" << i << " " << stat[i] << " " << cst[i] << "par: " << anc[i][0] << "\n";
// }
prec();
}
int getMinimumFuelCapacity(int X, int Y) {
int tl = 0, tr = m - 1;
while(tl < tr) {
int tm = (tl + tr) >> 1;
if(check(edges[tm][0], X, Y)) {
tr = tm;
}
else {
tl = tm + 1;
}
}
if(!check(edges[tl][0], X, Y)) {
tl++;
}
// cout << check(4, X, Y) << " val4" << endl;
if(tl >= m) return -1;
return edges[tl][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
72 ms |
25604 KB |
Output is correct |
10 |
Correct |
94 ms |
31312 KB |
Output is correct |
11 |
Correct |
91 ms |
31060 KB |
Output is correct |
12 |
Correct |
92 ms |
32712 KB |
Output is correct |
13 |
Correct |
99 ms |
32712 KB |
Output is correct |
14 |
Correct |
128 ms |
25904 KB |
Output is correct |
15 |
Correct |
665 ms |
35512 KB |
Output is correct |
16 |
Correct |
657 ms |
34576 KB |
Output is correct |
17 |
Correct |
687 ms |
36580 KB |
Output is correct |
18 |
Correct |
800 ms |
36432 KB |
Output is correct |
19 |
Correct |
337 ms |
10204 KB |
Output is correct |
20 |
Correct |
611 ms |
35652 KB |
Output is correct |
21 |
Correct |
669 ms |
34116 KB |
Output is correct |
22 |
Correct |
709 ms |
36436 KB |
Output is correct |
23 |
Correct |
894 ms |
36796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1141 ms |
33908 KB |
Output is correct |
4 |
Correct |
1183 ms |
35856 KB |
Output is correct |
5 |
Correct |
1107 ms |
34596 KB |
Output is correct |
6 |
Correct |
1180 ms |
35232 KB |
Output is correct |
7 |
Correct |
1245 ms |
35284 KB |
Output is correct |
8 |
Correct |
1106 ms |
33700 KB |
Output is correct |
9 |
Correct |
1156 ms |
35100 KB |
Output is correct |
10 |
Correct |
1172 ms |
33772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
700 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
700 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
704 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
72 ms |
25604 KB |
Output is correct |
11 |
Correct |
94 ms |
31312 KB |
Output is correct |
12 |
Correct |
91 ms |
31060 KB |
Output is correct |
13 |
Correct |
92 ms |
32712 KB |
Output is correct |
14 |
Correct |
99 ms |
32712 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
700 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
700 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
704 KB |
Output is correct |
33 |
Correct |
1 ms |
860 KB |
Output is correct |
34 |
Correct |
11 ms |
4696 KB |
Output is correct |
35 |
Correct |
101 ms |
32432 KB |
Output is correct |
36 |
Correct |
93 ms |
32340 KB |
Output is correct |
37 |
Correct |
90 ms |
32396 KB |
Output is correct |
38 |
Correct |
86 ms |
31960 KB |
Output is correct |
39 |
Correct |
86 ms |
31568 KB |
Output is correct |
40 |
Correct |
80 ms |
29124 KB |
Output is correct |
41 |
Correct |
89 ms |
32580 KB |
Output is correct |
42 |
Correct |
85 ms |
32316 KB |
Output is correct |
43 |
Correct |
103 ms |
32336 KB |
Output is correct |
44 |
Correct |
93 ms |
32720 KB |
Output is correct |
45 |
Correct |
122 ms |
37940 KB |
Output is correct |
46 |
Correct |
84 ms |
32416 KB |
Output is correct |
47 |
Correct |
96 ms |
32368 KB |
Output is correct |
48 |
Correct |
115 ms |
33940 KB |
Output is correct |
49 |
Correct |
84 ms |
28240 KB |
Output is correct |
50 |
Correct |
68 ms |
22604 KB |
Output is correct |
51 |
Correct |
102 ms |
32388 KB |
Output is correct |
52 |
Correct |
124 ms |
43408 KB |
Output is correct |
53 |
Correct |
145 ms |
46672 KB |
Output is correct |
54 |
Correct |
145 ms |
50000 KB |
Output is correct |
55 |
Correct |
98 ms |
32188 KB |
Output is correct |
56 |
Correct |
153 ms |
45440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
72 ms |
25604 KB |
Output is correct |
10 |
Correct |
94 ms |
31312 KB |
Output is correct |
11 |
Correct |
91 ms |
31060 KB |
Output is correct |
12 |
Correct |
92 ms |
32712 KB |
Output is correct |
13 |
Correct |
99 ms |
32712 KB |
Output is correct |
14 |
Correct |
128 ms |
25904 KB |
Output is correct |
15 |
Correct |
665 ms |
35512 KB |
Output is correct |
16 |
Correct |
657 ms |
34576 KB |
Output is correct |
17 |
Correct |
687 ms |
36580 KB |
Output is correct |
18 |
Correct |
800 ms |
36432 KB |
Output is correct |
19 |
Correct |
1141 ms |
33908 KB |
Output is correct |
20 |
Correct |
1183 ms |
35856 KB |
Output is correct |
21 |
Correct |
1107 ms |
34596 KB |
Output is correct |
22 |
Correct |
1180 ms |
35232 KB |
Output is correct |
23 |
Correct |
1245 ms |
35284 KB |
Output is correct |
24 |
Correct |
1106 ms |
33700 KB |
Output is correct |
25 |
Correct |
1156 ms |
35100 KB |
Output is correct |
26 |
Correct |
1172 ms |
33772 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
440 KB |
Output is correct |
31 |
Correct |
1 ms |
700 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
11 ms |
4696 KB |
Output is correct |
37 |
Correct |
101 ms |
32432 KB |
Output is correct |
38 |
Correct |
93 ms |
32340 KB |
Output is correct |
39 |
Correct |
90 ms |
32396 KB |
Output is correct |
40 |
Correct |
86 ms |
31960 KB |
Output is correct |
41 |
Correct |
86 ms |
31568 KB |
Output is correct |
42 |
Correct |
80 ms |
29124 KB |
Output is correct |
43 |
Correct |
89 ms |
32580 KB |
Output is correct |
44 |
Correct |
85 ms |
32316 KB |
Output is correct |
45 |
Correct |
103 ms |
32336 KB |
Output is correct |
46 |
Correct |
93 ms |
32720 KB |
Output is correct |
47 |
Correct |
54 ms |
4700 KB |
Output is correct |
48 |
Correct |
669 ms |
36264 KB |
Output is correct |
49 |
Correct |
647 ms |
36180 KB |
Output is correct |
50 |
Correct |
689 ms |
36020 KB |
Output is correct |
51 |
Correct |
727 ms |
35924 KB |
Output is correct |
52 |
Correct |
701 ms |
34128 KB |
Output is correct |
53 |
Correct |
676 ms |
25868 KB |
Output is correct |
54 |
Correct |
665 ms |
36564 KB |
Output is correct |
55 |
Correct |
651 ms |
36312 KB |
Output is correct |
56 |
Correct |
970 ms |
36276 KB |
Output is correct |
57 |
Correct |
752 ms |
36416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
72 ms |
25604 KB |
Output is correct |
11 |
Correct |
94 ms |
31312 KB |
Output is correct |
12 |
Correct |
91 ms |
31060 KB |
Output is correct |
13 |
Correct |
92 ms |
32712 KB |
Output is correct |
14 |
Correct |
99 ms |
32712 KB |
Output is correct |
15 |
Correct |
128 ms |
25904 KB |
Output is correct |
16 |
Correct |
665 ms |
35512 KB |
Output is correct |
17 |
Correct |
657 ms |
34576 KB |
Output is correct |
18 |
Correct |
687 ms |
36580 KB |
Output is correct |
19 |
Correct |
800 ms |
36432 KB |
Output is correct |
20 |
Correct |
1141 ms |
33908 KB |
Output is correct |
21 |
Correct |
1183 ms |
35856 KB |
Output is correct |
22 |
Correct |
1107 ms |
34596 KB |
Output is correct |
23 |
Correct |
1180 ms |
35232 KB |
Output is correct |
24 |
Correct |
1245 ms |
35284 KB |
Output is correct |
25 |
Correct |
1106 ms |
33700 KB |
Output is correct |
26 |
Correct |
1156 ms |
35100 KB |
Output is correct |
27 |
Correct |
1172 ms |
33772 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
440 KB |
Output is correct |
32 |
Correct |
1 ms |
700 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
11 ms |
4696 KB |
Output is correct |
38 |
Correct |
101 ms |
32432 KB |
Output is correct |
39 |
Correct |
93 ms |
32340 KB |
Output is correct |
40 |
Correct |
90 ms |
32396 KB |
Output is correct |
41 |
Correct |
86 ms |
31960 KB |
Output is correct |
42 |
Correct |
86 ms |
31568 KB |
Output is correct |
43 |
Correct |
80 ms |
29124 KB |
Output is correct |
44 |
Correct |
89 ms |
32580 KB |
Output is correct |
45 |
Correct |
85 ms |
32316 KB |
Output is correct |
46 |
Correct |
103 ms |
32336 KB |
Output is correct |
47 |
Correct |
93 ms |
32720 KB |
Output is correct |
48 |
Correct |
54 ms |
4700 KB |
Output is correct |
49 |
Correct |
669 ms |
36264 KB |
Output is correct |
50 |
Correct |
647 ms |
36180 KB |
Output is correct |
51 |
Correct |
689 ms |
36020 KB |
Output is correct |
52 |
Correct |
727 ms |
35924 KB |
Output is correct |
53 |
Correct |
701 ms |
34128 KB |
Output is correct |
54 |
Correct |
676 ms |
25868 KB |
Output is correct |
55 |
Correct |
665 ms |
36564 KB |
Output is correct |
56 |
Correct |
651 ms |
36312 KB |
Output is correct |
57 |
Correct |
970 ms |
36276 KB |
Output is correct |
58 |
Correct |
752 ms |
36416 KB |
Output is correct |
59 |
Correct |
337 ms |
10204 KB |
Output is correct |
60 |
Correct |
611 ms |
35652 KB |
Output is correct |
61 |
Correct |
669 ms |
34116 KB |
Output is correct |
62 |
Correct |
709 ms |
36436 KB |
Output is correct |
63 |
Correct |
894 ms |
36796 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
1 ms |
604 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
1 ms |
700 KB |
Output is correct |
70 |
Correct |
1 ms |
860 KB |
Output is correct |
71 |
Correct |
1 ms |
860 KB |
Output is correct |
72 |
Correct |
1 ms |
704 KB |
Output is correct |
73 |
Correct |
1 ms |
860 KB |
Output is correct |
74 |
Correct |
122 ms |
37940 KB |
Output is correct |
75 |
Correct |
84 ms |
32416 KB |
Output is correct |
76 |
Correct |
96 ms |
32368 KB |
Output is correct |
77 |
Correct |
115 ms |
33940 KB |
Output is correct |
78 |
Correct |
84 ms |
28240 KB |
Output is correct |
79 |
Correct |
68 ms |
22604 KB |
Output is correct |
80 |
Correct |
102 ms |
32388 KB |
Output is correct |
81 |
Correct |
124 ms |
43408 KB |
Output is correct |
82 |
Correct |
145 ms |
46672 KB |
Output is correct |
83 |
Correct |
145 ms |
50000 KB |
Output is correct |
84 |
Correct |
98 ms |
32188 KB |
Output is correct |
85 |
Correct |
153 ms |
45440 KB |
Output is correct |
86 |
Correct |
217 ms |
14676 KB |
Output is correct |
87 |
Correct |
662 ms |
36284 KB |
Output is correct |
88 |
Correct |
660 ms |
36280 KB |
Output is correct |
89 |
Correct |
936 ms |
35920 KB |
Output is correct |
90 |
Correct |
818 ms |
33528 KB |
Output is correct |
91 |
Correct |
855 ms |
32368 KB |
Output is correct |
92 |
Correct |
1091 ms |
35136 KB |
Output is correct |
93 |
Correct |
909 ms |
46996 KB |
Output is correct |
94 |
Correct |
1268 ms |
50248 KB |
Output is correct |
95 |
Correct |
850 ms |
53840 KB |
Output is correct |
96 |
Correct |
1151 ms |
36152 KB |
Output is correct |
97 |
Correct |
1323 ms |
42848 KB |
Output is correct |