#include "swap.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e9;
const int L = 2e5+1;
vi getter(L,inf);
struct DSU {
int n;
vi dad,change,sz;
DSU(){};
DSU(int nn) {
n = nn;
dad.resize(n),change.assign(n,inf),sz.assign(n,1);
iota(dad.begin(),dad.end(),0ll);
}
int find(int x,int t) {
if (change[x]==inf || change[x] > t) return x;
return find(dad[x],t);
}
void unite(int x,int y,int t) {
int a = find(x,t);
int b = find(y,t);
if (a == b) {
getter[a] = min(getter[a],t);
return;
}
if (sz[a] < sz[b]) swap(a,b);
dad[b] = a;
sz[a]+=sz[b];
change[b] = t;
if (getter[b] != inf) getter[a] = min(getter[a],t);
}
};
vi vv;
int idx(int xx) {
return upper_bound(all(vv),xx)-vv.begin();
}
map<int,int> realy;
DSU dsu;
int nn;
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
nn = N;
for (int i=0;i<M;i++) vv.push_back(W[i]);
sort(all(vv));
vv.erase(unique(all(vv)),vv.end());
int cc = 1;
for (auto it : vv) realy[cc++] = it;
dsu = DSU(N);
vector<pair<int,pii>> edges;
for (int i=0;i<M;i++) edges.push_back({idx(W[i]),{U[i],V[i]}});
vi edg(N,0);
sort(all(edges));
for (auto it : edges) {
dsu.unite(it.ss.ff,it.ss.ss,it.ff);
edg[it.ss.ff]++;
edg[it.ss.ss]++;
if (edg[it.ss.ff] == 3 || edg[it.ss.ss] == 3) {
getter[dsu.find(it.ss.ff,it.ff)] = min(it.ff,getter[dsu.find(it.ss.ff,it.ff)]);
}
}
}
int getMinimumFuelCapacity(int X, int Y) {
int sz = vv.size();
int l = 1;
int r = sz;
while (l<=r) {
int m = (l+r) >> 1;
if (dsu.find(X,m) != dsu.find(Y,m)) {
l = m+1;
continue;
}
int p = dsu.find(X,m);
if (getter[p] > m) l = m+1;
else r = m-1;
}
if (l <= sz) return realy[l];
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
39 ms |
9884 KB |
Output is correct |
10 |
Correct |
46 ms |
11344 KB |
Output is correct |
11 |
Correct |
45 ms |
11088 KB |
Output is correct |
12 |
Correct |
46 ms |
11600 KB |
Output is correct |
13 |
Correct |
46 ms |
11588 KB |
Output is correct |
14 |
Correct |
44 ms |
9800 KB |
Output is correct |
15 |
Correct |
119 ms |
12872 KB |
Output is correct |
16 |
Correct |
118 ms |
12616 KB |
Output is correct |
17 |
Correct |
128 ms |
13124 KB |
Output is correct |
18 |
Correct |
91 ms |
13124 KB |
Output is correct |
19 |
Correct |
67 ms |
5980 KB |
Output is correct |
20 |
Correct |
138 ms |
12796 KB |
Output is correct |
21 |
Correct |
186 ms |
12832 KB |
Output is correct |
22 |
Correct |
142 ms |
13128 KB |
Output is correct |
23 |
Correct |
104 ms |
13144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
163 ms |
12568 KB |
Output is correct |
4 |
Correct |
135 ms |
13048 KB |
Output is correct |
5 |
Correct |
127 ms |
12872 KB |
Output is correct |
6 |
Correct |
125 ms |
13128 KB |
Output is correct |
7 |
Correct |
153 ms |
12872 KB |
Output is correct |
8 |
Correct |
140 ms |
12612 KB |
Output is correct |
9 |
Correct |
131 ms |
12856 KB |
Output is correct |
10 |
Correct |
140 ms |
12616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1284 KB |
Output is correct |
26 |
Correct |
1 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
0 ms |
1112 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
39 ms |
9884 KB |
Output is correct |
11 |
Correct |
46 ms |
11344 KB |
Output is correct |
12 |
Correct |
45 ms |
11088 KB |
Output is correct |
13 |
Correct |
46 ms |
11600 KB |
Output is correct |
14 |
Correct |
46 ms |
11588 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1372 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
1 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
1284 KB |
Output is correct |
31 |
Correct |
1 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
2 ms |
1372 KB |
Output is correct |
34 |
Correct |
6 ms |
2652 KB |
Output is correct |
35 |
Correct |
46 ms |
11344 KB |
Output is correct |
36 |
Correct |
69 ms |
11332 KB |
Output is correct |
37 |
Correct |
46 ms |
11340 KB |
Output is correct |
38 |
Correct |
45 ms |
11280 KB |
Output is correct |
39 |
Correct |
45 ms |
11124 KB |
Output is correct |
40 |
Correct |
43 ms |
10568 KB |
Output is correct |
41 |
Correct |
50 ms |
11600 KB |
Output is correct |
42 |
Correct |
46 ms |
13128 KB |
Output is correct |
43 |
Correct |
46 ms |
13128 KB |
Output is correct |
44 |
Correct |
47 ms |
13764 KB |
Output is correct |
45 |
Correct |
73 ms |
20772 KB |
Output is correct |
46 |
Correct |
46 ms |
13256 KB |
Output is correct |
47 |
Correct |
46 ms |
13224 KB |
Output is correct |
48 |
Correct |
53 ms |
14152 KB |
Output is correct |
49 |
Correct |
78 ms |
20480 KB |
Output is correct |
50 |
Correct |
58 ms |
14260 KB |
Output is correct |
51 |
Correct |
65 ms |
15936 KB |
Output is correct |
52 |
Correct |
89 ms |
21516 KB |
Output is correct |
53 |
Correct |
96 ms |
23684 KB |
Output is correct |
54 |
Correct |
149 ms |
25796 KB |
Output is correct |
55 |
Correct |
46 ms |
13128 KB |
Output is correct |
56 |
Correct |
91 ms |
23160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
39 ms |
9884 KB |
Output is correct |
10 |
Correct |
46 ms |
11344 KB |
Output is correct |
11 |
Correct |
45 ms |
11088 KB |
Output is correct |
12 |
Correct |
46 ms |
11600 KB |
Output is correct |
13 |
Correct |
46 ms |
11588 KB |
Output is correct |
14 |
Correct |
44 ms |
9800 KB |
Output is correct |
15 |
Correct |
119 ms |
12872 KB |
Output is correct |
16 |
Correct |
118 ms |
12616 KB |
Output is correct |
17 |
Correct |
128 ms |
13124 KB |
Output is correct |
18 |
Correct |
91 ms |
13124 KB |
Output is correct |
19 |
Correct |
163 ms |
12568 KB |
Output is correct |
20 |
Correct |
135 ms |
13048 KB |
Output is correct |
21 |
Correct |
127 ms |
12872 KB |
Output is correct |
22 |
Correct |
125 ms |
13128 KB |
Output is correct |
23 |
Correct |
153 ms |
12872 KB |
Output is correct |
24 |
Correct |
140 ms |
12612 KB |
Output is correct |
25 |
Correct |
131 ms |
12856 KB |
Output is correct |
26 |
Correct |
140 ms |
12616 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
1 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
1 ms |
1116 KB |
Output is correct |
34 |
Correct |
1 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
1116 KB |
Output is correct |
36 |
Correct |
6 ms |
2652 KB |
Output is correct |
37 |
Correct |
46 ms |
11344 KB |
Output is correct |
38 |
Correct |
69 ms |
11332 KB |
Output is correct |
39 |
Correct |
46 ms |
11340 KB |
Output is correct |
40 |
Correct |
45 ms |
11280 KB |
Output is correct |
41 |
Correct |
45 ms |
11124 KB |
Output is correct |
42 |
Correct |
43 ms |
10568 KB |
Output is correct |
43 |
Correct |
50 ms |
11600 KB |
Output is correct |
44 |
Correct |
46 ms |
13128 KB |
Output is correct |
45 |
Correct |
46 ms |
13128 KB |
Output is correct |
46 |
Correct |
47 ms |
13764 KB |
Output is correct |
47 |
Correct |
13 ms |
3208 KB |
Output is correct |
48 |
Correct |
139 ms |
17088 KB |
Output is correct |
49 |
Correct |
141 ms |
17224 KB |
Output is correct |
50 |
Correct |
157 ms |
17064 KB |
Output is correct |
51 |
Correct |
166 ms |
16964 KB |
Output is correct |
52 |
Correct |
135 ms |
16452 KB |
Output is correct |
53 |
Correct |
118 ms |
14124 KB |
Output is correct |
54 |
Correct |
144 ms |
17736 KB |
Output is correct |
55 |
Correct |
141 ms |
17224 KB |
Output is correct |
56 |
Correct |
139 ms |
17068 KB |
Output is correct |
57 |
Correct |
153 ms |
17736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
0 ms |
1112 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
39 ms |
9884 KB |
Output is correct |
11 |
Correct |
46 ms |
11344 KB |
Output is correct |
12 |
Correct |
45 ms |
11088 KB |
Output is correct |
13 |
Correct |
46 ms |
11600 KB |
Output is correct |
14 |
Correct |
46 ms |
11588 KB |
Output is correct |
15 |
Correct |
44 ms |
9800 KB |
Output is correct |
16 |
Correct |
119 ms |
12872 KB |
Output is correct |
17 |
Correct |
118 ms |
12616 KB |
Output is correct |
18 |
Correct |
128 ms |
13124 KB |
Output is correct |
19 |
Correct |
91 ms |
13124 KB |
Output is correct |
20 |
Correct |
163 ms |
12568 KB |
Output is correct |
21 |
Correct |
135 ms |
13048 KB |
Output is correct |
22 |
Correct |
127 ms |
12872 KB |
Output is correct |
23 |
Correct |
125 ms |
13128 KB |
Output is correct |
24 |
Correct |
153 ms |
12872 KB |
Output is correct |
25 |
Correct |
140 ms |
12612 KB |
Output is correct |
26 |
Correct |
131 ms |
12856 KB |
Output is correct |
27 |
Correct |
140 ms |
12616 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
1 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
1 ms |
1116 KB |
Output is correct |
34 |
Correct |
1 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
1116 KB |
Output is correct |
36 |
Correct |
1 ms |
1116 KB |
Output is correct |
37 |
Correct |
6 ms |
2652 KB |
Output is correct |
38 |
Correct |
46 ms |
11344 KB |
Output is correct |
39 |
Correct |
69 ms |
11332 KB |
Output is correct |
40 |
Correct |
46 ms |
11340 KB |
Output is correct |
41 |
Correct |
45 ms |
11280 KB |
Output is correct |
42 |
Correct |
45 ms |
11124 KB |
Output is correct |
43 |
Correct |
43 ms |
10568 KB |
Output is correct |
44 |
Correct |
50 ms |
11600 KB |
Output is correct |
45 |
Correct |
46 ms |
13128 KB |
Output is correct |
46 |
Correct |
46 ms |
13128 KB |
Output is correct |
47 |
Correct |
47 ms |
13764 KB |
Output is correct |
48 |
Correct |
13 ms |
3208 KB |
Output is correct |
49 |
Correct |
139 ms |
17088 KB |
Output is correct |
50 |
Correct |
141 ms |
17224 KB |
Output is correct |
51 |
Correct |
157 ms |
17064 KB |
Output is correct |
52 |
Correct |
166 ms |
16964 KB |
Output is correct |
53 |
Correct |
135 ms |
16452 KB |
Output is correct |
54 |
Correct |
118 ms |
14124 KB |
Output is correct |
55 |
Correct |
144 ms |
17736 KB |
Output is correct |
56 |
Correct |
141 ms |
17224 KB |
Output is correct |
57 |
Correct |
139 ms |
17068 KB |
Output is correct |
58 |
Correct |
153 ms |
17736 KB |
Output is correct |
59 |
Correct |
67 ms |
5980 KB |
Output is correct |
60 |
Correct |
138 ms |
12796 KB |
Output is correct |
61 |
Correct |
186 ms |
12832 KB |
Output is correct |
62 |
Correct |
142 ms |
13128 KB |
Output is correct |
63 |
Correct |
104 ms |
13144 KB |
Output is correct |
64 |
Correct |
1 ms |
1116 KB |
Output is correct |
65 |
Correct |
1 ms |
1116 KB |
Output is correct |
66 |
Correct |
1 ms |
1116 KB |
Output is correct |
67 |
Correct |
1 ms |
1372 KB |
Output is correct |
68 |
Correct |
1 ms |
1116 KB |
Output is correct |
69 |
Correct |
1 ms |
1372 KB |
Output is correct |
70 |
Correct |
2 ms |
1284 KB |
Output is correct |
71 |
Correct |
1 ms |
1372 KB |
Output is correct |
72 |
Correct |
1 ms |
1116 KB |
Output is correct |
73 |
Correct |
2 ms |
1372 KB |
Output is correct |
74 |
Correct |
73 ms |
20772 KB |
Output is correct |
75 |
Correct |
46 ms |
13256 KB |
Output is correct |
76 |
Correct |
46 ms |
13224 KB |
Output is correct |
77 |
Correct |
53 ms |
14152 KB |
Output is correct |
78 |
Correct |
78 ms |
20480 KB |
Output is correct |
79 |
Correct |
58 ms |
14260 KB |
Output is correct |
80 |
Correct |
65 ms |
15936 KB |
Output is correct |
81 |
Correct |
89 ms |
21516 KB |
Output is correct |
82 |
Correct |
96 ms |
23684 KB |
Output is correct |
83 |
Correct |
149 ms |
25796 KB |
Output is correct |
84 |
Correct |
46 ms |
13128 KB |
Output is correct |
85 |
Correct |
91 ms |
23160 KB |
Output is correct |
86 |
Correct |
47 ms |
8088 KB |
Output is correct |
87 |
Correct |
141 ms |
17008 KB |
Output is correct |
88 |
Correct |
142 ms |
17132 KB |
Output is correct |
89 |
Correct |
164 ms |
17508 KB |
Output is correct |
90 |
Correct |
164 ms |
23784 KB |
Output is correct |
91 |
Correct |
149 ms |
23748 KB |
Output is correct |
92 |
Correct |
162 ms |
19272 KB |
Output is correct |
93 |
Correct |
183 ms |
25076 KB |
Output is correct |
94 |
Correct |
196 ms |
28100 KB |
Output is correct |
95 |
Correct |
218 ms |
28636 KB |
Output is correct |
96 |
Correct |
125 ms |
17216 KB |
Output is correct |
97 |
Correct |
168 ms |
23776 KB |
Output is correct |