#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;
getter[a] = min(getter[a],getter[b]);
}
};
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
1112 KB |
Output is correct |
9 |
Correct |
38 ms |
11336 KB |
Output is correct |
10 |
Correct |
47 ms |
13252 KB |
Output is correct |
11 |
Correct |
46 ms |
13124 KB |
Output is correct |
12 |
Correct |
47 ms |
13696 KB |
Output is correct |
13 |
Correct |
47 ms |
13636 KB |
Output is correct |
14 |
Correct |
44 ms |
11816 KB |
Output is correct |
15 |
Correct |
123 ms |
17220 KB |
Output is correct |
16 |
Correct |
121 ms |
16964 KB |
Output is correct |
17 |
Correct |
127 ms |
17632 KB |
Output is correct |
18 |
Correct |
90 ms |
17736 KB |
Output is correct |
19 |
Correct |
66 ms |
8020 KB |
Output is correct |
20 |
Correct |
133 ms |
17056 KB |
Output is correct |
21 |
Correct |
147 ms |
17120 KB |
Output is correct |
22 |
Correct |
144 ms |
17736 KB |
Output is correct |
23 |
Correct |
106 ms |
17520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
121 ms |
16456 KB |
Output is correct |
4 |
Correct |
125 ms |
16968 KB |
Output is correct |
5 |
Correct |
133 ms |
16712 KB |
Output is correct |
6 |
Correct |
122 ms |
16968 KB |
Output is correct |
7 |
Correct |
131 ms |
16804 KB |
Output is correct |
8 |
Correct |
124 ms |
16456 KB |
Output is correct |
9 |
Correct |
126 ms |
16712 KB |
Output is correct |
10 |
Correct |
129 ms |
16456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1112 KB |
Output is correct |
9 |
Correct |
0 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 |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1248 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Incorrect |
1 ms |
1372 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1112 KB |
Output is correct |
10 |
Correct |
38 ms |
11336 KB |
Output is correct |
11 |
Correct |
47 ms |
13252 KB |
Output is correct |
12 |
Correct |
46 ms |
13124 KB |
Output is correct |
13 |
Correct |
47 ms |
13696 KB |
Output is correct |
14 |
Correct |
47 ms |
13636 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 |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
1248 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Incorrect |
1 ms |
1372 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1112 KB |
Output is correct |
9 |
Correct |
38 ms |
11336 KB |
Output is correct |
10 |
Correct |
47 ms |
13252 KB |
Output is correct |
11 |
Correct |
46 ms |
13124 KB |
Output is correct |
12 |
Correct |
47 ms |
13696 KB |
Output is correct |
13 |
Correct |
47 ms |
13636 KB |
Output is correct |
14 |
Correct |
44 ms |
11816 KB |
Output is correct |
15 |
Correct |
123 ms |
17220 KB |
Output is correct |
16 |
Correct |
121 ms |
16964 KB |
Output is correct |
17 |
Correct |
127 ms |
17632 KB |
Output is correct |
18 |
Correct |
90 ms |
17736 KB |
Output is correct |
19 |
Correct |
121 ms |
16456 KB |
Output is correct |
20 |
Correct |
125 ms |
16968 KB |
Output is correct |
21 |
Correct |
133 ms |
16712 KB |
Output is correct |
22 |
Correct |
122 ms |
16968 KB |
Output is correct |
23 |
Correct |
131 ms |
16804 KB |
Output is correct |
24 |
Correct |
124 ms |
16456 KB |
Output is correct |
25 |
Correct |
126 ms |
16712 KB |
Output is correct |
26 |
Correct |
129 ms |
16456 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 |
7 ms |
2944 KB |
Output is correct |
37 |
Correct |
47 ms |
13300 KB |
Output is correct |
38 |
Correct |
46 ms |
13216 KB |
Output is correct |
39 |
Correct |
54 ms |
13128 KB |
Output is correct |
40 |
Correct |
46 ms |
13124 KB |
Output is correct |
41 |
Correct |
49 ms |
13100 KB |
Output is correct |
42 |
Correct |
47 ms |
12240 KB |
Output is correct |
43 |
Incorrect |
55 ms |
13640 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1112 KB |
Output is correct |
10 |
Correct |
38 ms |
11336 KB |
Output is correct |
11 |
Correct |
47 ms |
13252 KB |
Output is correct |
12 |
Correct |
46 ms |
13124 KB |
Output is correct |
13 |
Correct |
47 ms |
13696 KB |
Output is correct |
14 |
Correct |
47 ms |
13636 KB |
Output is correct |
15 |
Correct |
44 ms |
11816 KB |
Output is correct |
16 |
Correct |
123 ms |
17220 KB |
Output is correct |
17 |
Correct |
121 ms |
16964 KB |
Output is correct |
18 |
Correct |
127 ms |
17632 KB |
Output is correct |
19 |
Correct |
90 ms |
17736 KB |
Output is correct |
20 |
Correct |
121 ms |
16456 KB |
Output is correct |
21 |
Correct |
125 ms |
16968 KB |
Output is correct |
22 |
Correct |
133 ms |
16712 KB |
Output is correct |
23 |
Correct |
122 ms |
16968 KB |
Output is correct |
24 |
Correct |
131 ms |
16804 KB |
Output is correct |
25 |
Correct |
124 ms |
16456 KB |
Output is correct |
26 |
Correct |
126 ms |
16712 KB |
Output is correct |
27 |
Correct |
129 ms |
16456 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 |
7 ms |
2944 KB |
Output is correct |
38 |
Correct |
47 ms |
13300 KB |
Output is correct |
39 |
Correct |
46 ms |
13216 KB |
Output is correct |
40 |
Correct |
54 ms |
13128 KB |
Output is correct |
41 |
Correct |
46 ms |
13124 KB |
Output is correct |
42 |
Correct |
49 ms |
13100 KB |
Output is correct |
43 |
Correct |
47 ms |
12240 KB |
Output is correct |
44 |
Incorrect |
55 ms |
13640 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |