#include "swap.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int N = 5e5 + 5;
const int infi = INT_MAX;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define F first
#define S second
struct dsu{
int pw[N];
vector<pii> p[N], cnt1[N], cnt2[N], sz[N];
dsu(int n){
for(int i = 1; i <= n; i++){
p[i] = {{-1, i}};
sz[i] = {{-1, 1}};
cnt1[i] = {{-1, 0}};
cnt2[i] = {{-1, 0}};
pw[i] = 0;
}
}
dsu(){
}
int getp(int v, int t){
int pr = (--upper_bound(p[v].begin(), p[v].end(),mp(t, infi)))->S;
if(pr == v)
return v;
return getp(pr, t);
}
void upd(int v, int nw, int t){
if(nw == 1)
cnt1[v].pb({t, cnt1[v].back().S - 1});
if(nw == 2)
cnt2[v].pb({t, cnt2[v].back().S - 1});
if(nw == 0)
cnt1[v].pb({t, cnt1[v].back().S + 1});
if(nw == 1)
cnt2[v].pb({t, cnt2[v].back().S + 1});
}
void uni(int a, int b, int t){
int n1 = pw[a];
int n2 = pw[b];
//cout << n1 << ' ' << n2 << '\n';
pw[a]++;
pw[b]++;
a = getp(a, t);
b = getp(b, t);
if(a == b){
upd(a, n1, t);
upd(a, n2, t);
return;
}
if(sz[a] > sz[b])
swap(a, b);
p[a].pb({t, b});
sz[b].pb({t, sz[a].back().S + sz[b].back().S});
cnt1[b].pb({t, cnt1[a].back().S + cnt1[b].back().S});
cnt2[b].pb({t, cnt2[a].back().S + cnt2[b].back().S});
upd(b, n1, t);
upd(b, n2, t);
}
};
int n, m;
vector<pair<int, pair<int, int>>> edges;
dsu ds;
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N;
m = M;
for(int i = 0; i < m; i++){
U[i]++;
V[i]++;
edges.pb({W[i], {V[i], U[i]}});
}
sort(edges.begin(), edges.end());
ds = dsu(n);
for(int i = 0; i < m; i++){
ds.uni(edges[i].S.F, edges[i].S.S, i);
/*cout << edges[i].S.F << ' ' << edges[i].S.S << '\n';
cout << "comp: ";
for(int j = 1; j <= n; j++){
cout << ds.getp(j, infi) << ' ';
}
cout << '\n';
cout << "cnt1: ";
for(int i = 1; i <= n; i++){
cout << ds.cnt1[ds.getp(i, infi)].back().S << ' ';
}
cout << '\n';
cout << "cnt2: ";
for(int i = 1; i <= n; i++){
cout << ds.cnt2[ds.getp(i, infi)].back().S << ' ';
}
cout << '\n';*/
}
}
int getMinimumFuelCapacity(int X, int Y) {
X++;
Y++;
int lo = -1, hi = m;
while(lo + 1 < hi){
int m = (lo + hi) / 2;
int x = ds.getp(X, m), y = ds.getp(Y, m);
if(x != y){
lo = m;
continue;
}
int c1 = (--upper_bound(ds.cnt1[x].begin(), ds.cnt1[x].end(),mp(m, infi)))->S;
int c2 = (--upper_bound(ds.cnt2[x].begin(), ds.cnt2[x].end(),mp(m, infi)))->S;
int sz = (--upper_bound(ds.sz[x].begin(), ds.sz[x].end(),mp(m, infi)))->S;
if(c1 == 2 && c2 == sz - 2){
lo = m;
continue;
}
hi = m;
}
if(hi == m)
return -1;
return edges[hi].F;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98132 KB |
Output is correct |
2 |
Correct |
60 ms |
98184 KB |
Output is correct |
3 |
Correct |
52 ms |
98168 KB |
Output is correct |
4 |
Correct |
54 ms |
98128 KB |
Output is correct |
5 |
Correct |
56 ms |
98424 KB |
Output is correct |
6 |
Correct |
71 ms |
98388 KB |
Output is correct |
7 |
Correct |
73 ms |
98388 KB |
Output is correct |
8 |
Correct |
54 ms |
98436 KB |
Output is correct |
9 |
Correct |
166 ms |
118780 KB |
Output is correct |
10 |
Correct |
170 ms |
123248 KB |
Output is correct |
11 |
Correct |
168 ms |
122816 KB |
Output is correct |
12 |
Correct |
198 ms |
124280 KB |
Output is correct |
13 |
Correct |
137 ms |
123680 KB |
Output is correct |
14 |
Correct |
177 ms |
118972 KB |
Output is correct |
15 |
Correct |
526 ms |
127572 KB |
Output is correct |
16 |
Correct |
498 ms |
126756 KB |
Output is correct |
17 |
Correct |
486 ms |
128280 KB |
Output is correct |
18 |
Correct |
379 ms |
127136 KB |
Output is correct |
19 |
Correct |
288 ms |
107428 KB |
Output is correct |
20 |
Correct |
578 ms |
128696 KB |
Output is correct |
21 |
Correct |
466 ms |
128040 KB |
Output is correct |
22 |
Correct |
493 ms |
129796 KB |
Output is correct |
23 |
Correct |
354 ms |
127652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98132 KB |
Output is correct |
2 |
Correct |
60 ms |
98184 KB |
Output is correct |
3 |
Correct |
504 ms |
123800 KB |
Output is correct |
4 |
Correct |
458 ms |
124668 KB |
Output is correct |
5 |
Correct |
520 ms |
124252 KB |
Output is correct |
6 |
Correct |
455 ms |
124500 KB |
Output is correct |
7 |
Correct |
468 ms |
124480 KB |
Output is correct |
8 |
Correct |
461 ms |
123756 KB |
Output is correct |
9 |
Correct |
468 ms |
124228 KB |
Output is correct |
10 |
Correct |
463 ms |
123524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98132 KB |
Output is correct |
2 |
Correct |
60 ms |
98184 KB |
Output is correct |
3 |
Correct |
52 ms |
98168 KB |
Output is correct |
4 |
Correct |
54 ms |
98128 KB |
Output is correct |
5 |
Correct |
56 ms |
98424 KB |
Output is correct |
6 |
Correct |
71 ms |
98388 KB |
Output is correct |
7 |
Correct |
73 ms |
98388 KB |
Output is correct |
8 |
Correct |
54 ms |
98436 KB |
Output is correct |
9 |
Correct |
52 ms |
98128 KB |
Output is correct |
10 |
Correct |
53 ms |
98428 KB |
Output is correct |
11 |
Correct |
53 ms |
98384 KB |
Output is correct |
12 |
Correct |
55 ms |
98384 KB |
Output is correct |
13 |
Correct |
52 ms |
98384 KB |
Output is correct |
14 |
Correct |
52 ms |
98388 KB |
Output is correct |
15 |
Correct |
53 ms |
98384 KB |
Output is correct |
16 |
Correct |
53 ms |
98392 KB |
Output is correct |
17 |
Correct |
51 ms |
98372 KB |
Output is correct |
18 |
Correct |
52 ms |
98388 KB |
Output is correct |
19 |
Correct |
56 ms |
98384 KB |
Output is correct |
20 |
Correct |
57 ms |
98412 KB |
Output is correct |
21 |
Correct |
53 ms |
98344 KB |
Output is correct |
22 |
Correct |
53 ms |
98384 KB |
Output is correct |
23 |
Correct |
52 ms |
98348 KB |
Output is correct |
24 |
Correct |
52 ms |
98416 KB |
Output is correct |
25 |
Correct |
52 ms |
98500 KB |
Output is correct |
26 |
Correct |
52 ms |
98384 KB |
Output is correct |
27 |
Correct |
52 ms |
98508 KB |
Output is correct |
28 |
Correct |
52 ms |
98336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
98128 KB |
Output is correct |
2 |
Correct |
51 ms |
98132 KB |
Output is correct |
3 |
Correct |
60 ms |
98184 KB |
Output is correct |
4 |
Correct |
52 ms |
98168 KB |
Output is correct |
5 |
Correct |
54 ms |
98128 KB |
Output is correct |
6 |
Correct |
56 ms |
98424 KB |
Output is correct |
7 |
Correct |
71 ms |
98388 KB |
Output is correct |
8 |
Correct |
73 ms |
98388 KB |
Output is correct |
9 |
Correct |
54 ms |
98436 KB |
Output is correct |
10 |
Correct |
166 ms |
118780 KB |
Output is correct |
11 |
Correct |
170 ms |
123248 KB |
Output is correct |
12 |
Correct |
168 ms |
122816 KB |
Output is correct |
13 |
Correct |
198 ms |
124280 KB |
Output is correct |
14 |
Correct |
137 ms |
123680 KB |
Output is correct |
15 |
Correct |
53 ms |
98428 KB |
Output is correct |
16 |
Correct |
53 ms |
98384 KB |
Output is correct |
17 |
Correct |
55 ms |
98384 KB |
Output is correct |
18 |
Correct |
52 ms |
98384 KB |
Output is correct |
19 |
Correct |
52 ms |
98388 KB |
Output is correct |
20 |
Correct |
53 ms |
98384 KB |
Output is correct |
21 |
Correct |
53 ms |
98392 KB |
Output is correct |
22 |
Correct |
51 ms |
98372 KB |
Output is correct |
23 |
Correct |
52 ms |
98388 KB |
Output is correct |
24 |
Correct |
56 ms |
98384 KB |
Output is correct |
25 |
Correct |
57 ms |
98412 KB |
Output is correct |
26 |
Correct |
53 ms |
98344 KB |
Output is correct |
27 |
Correct |
53 ms |
98384 KB |
Output is correct |
28 |
Correct |
52 ms |
98348 KB |
Output is correct |
29 |
Correct |
52 ms |
98416 KB |
Output is correct |
30 |
Correct |
52 ms |
98500 KB |
Output is correct |
31 |
Correct |
52 ms |
98384 KB |
Output is correct |
32 |
Correct |
52 ms |
98508 KB |
Output is correct |
33 |
Correct |
52 ms |
98336 KB |
Output is correct |
34 |
Correct |
62 ms |
101588 KB |
Output is correct |
35 |
Correct |
158 ms |
123952 KB |
Output is correct |
36 |
Correct |
161 ms |
124068 KB |
Output is correct |
37 |
Correct |
158 ms |
124100 KB |
Output is correct |
38 |
Correct |
164 ms |
123588 KB |
Output is correct |
39 |
Correct |
174 ms |
123276 KB |
Output is correct |
40 |
Correct |
163 ms |
121000 KB |
Output is correct |
41 |
Correct |
163 ms |
124360 KB |
Output is correct |
42 |
Correct |
161 ms |
124060 KB |
Output is correct |
43 |
Correct |
131 ms |
122928 KB |
Output is correct |
44 |
Correct |
171 ms |
123592 KB |
Output is correct |
45 |
Correct |
244 ms |
122300 KB |
Output is correct |
46 |
Correct |
164 ms |
124012 KB |
Output is correct |
47 |
Correct |
165 ms |
123680 KB |
Output is correct |
48 |
Correct |
182 ms |
123072 KB |
Output is correct |
49 |
Correct |
118 ms |
106676 KB |
Output is correct |
50 |
Correct |
121 ms |
106268 KB |
Output is correct |
51 |
Correct |
257 ms |
118472 KB |
Output is correct |
52 |
Correct |
200 ms |
129476 KB |
Output is correct |
53 |
Correct |
201 ms |
131772 KB |
Output is correct |
54 |
Correct |
249 ms |
131400 KB |
Output is correct |
55 |
Correct |
127 ms |
122904 KB |
Output is correct |
56 |
Correct |
285 ms |
127936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
98132 KB |
Output is correct |
2 |
Correct |
60 ms |
98184 KB |
Output is correct |
3 |
Correct |
52 ms |
98168 KB |
Output is correct |
4 |
Correct |
54 ms |
98128 KB |
Output is correct |
5 |
Correct |
56 ms |
98424 KB |
Output is correct |
6 |
Correct |
71 ms |
98388 KB |
Output is correct |
7 |
Correct |
73 ms |
98388 KB |
Output is correct |
8 |
Correct |
54 ms |
98436 KB |
Output is correct |
9 |
Correct |
166 ms |
118780 KB |
Output is correct |
10 |
Correct |
170 ms |
123248 KB |
Output is correct |
11 |
Correct |
168 ms |
122816 KB |
Output is correct |
12 |
Correct |
198 ms |
124280 KB |
Output is correct |
13 |
Correct |
137 ms |
123680 KB |
Output is correct |
14 |
Correct |
177 ms |
118972 KB |
Output is correct |
15 |
Correct |
526 ms |
127572 KB |
Output is correct |
16 |
Correct |
498 ms |
126756 KB |
Output is correct |
17 |
Correct |
486 ms |
128280 KB |
Output is correct |
18 |
Correct |
379 ms |
127136 KB |
Output is correct |
19 |
Correct |
504 ms |
123800 KB |
Output is correct |
20 |
Correct |
458 ms |
124668 KB |
Output is correct |
21 |
Correct |
520 ms |
124252 KB |
Output is correct |
22 |
Correct |
455 ms |
124500 KB |
Output is correct |
23 |
Correct |
468 ms |
124480 KB |
Output is correct |
24 |
Correct |
461 ms |
123756 KB |
Output is correct |
25 |
Correct |
468 ms |
124228 KB |
Output is correct |
26 |
Correct |
463 ms |
123524 KB |
Output is correct |
27 |
Correct |
53 ms |
98428 KB |
Output is correct |
28 |
Correct |
53 ms |
98384 KB |
Output is correct |
29 |
Correct |
55 ms |
98384 KB |
Output is correct |
30 |
Correct |
52 ms |
98384 KB |
Output is correct |
31 |
Correct |
52 ms |
98388 KB |
Output is correct |
32 |
Correct |
53 ms |
98384 KB |
Output is correct |
33 |
Correct |
53 ms |
98392 KB |
Output is correct |
34 |
Correct |
51 ms |
98372 KB |
Output is correct |
35 |
Correct |
52 ms |
98388 KB |
Output is correct |
36 |
Correct |
62 ms |
101588 KB |
Output is correct |
37 |
Correct |
158 ms |
123952 KB |
Output is correct |
38 |
Correct |
161 ms |
124068 KB |
Output is correct |
39 |
Correct |
158 ms |
124100 KB |
Output is correct |
40 |
Correct |
164 ms |
123588 KB |
Output is correct |
41 |
Correct |
174 ms |
123276 KB |
Output is correct |
42 |
Correct |
163 ms |
121000 KB |
Output is correct |
43 |
Correct |
163 ms |
124360 KB |
Output is correct |
44 |
Correct |
161 ms |
124060 KB |
Output is correct |
45 |
Correct |
131 ms |
122928 KB |
Output is correct |
46 |
Correct |
171 ms |
123592 KB |
Output is correct |
47 |
Correct |
106 ms |
101940 KB |
Output is correct |
48 |
Correct |
476 ms |
128800 KB |
Output is correct |
49 |
Correct |
509 ms |
128916 KB |
Output is correct |
50 |
Correct |
497 ms |
128808 KB |
Output is correct |
51 |
Correct |
489 ms |
128568 KB |
Output is correct |
52 |
Correct |
522 ms |
127052 KB |
Output is correct |
53 |
Correct |
489 ms |
120760 KB |
Output is correct |
54 |
Correct |
533 ms |
129876 KB |
Output is correct |
55 |
Correct |
504 ms |
128812 KB |
Output is correct |
56 |
Execution timed out |
2071 ms |
126772 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
98128 KB |
Output is correct |
2 |
Correct |
51 ms |
98132 KB |
Output is correct |
3 |
Correct |
60 ms |
98184 KB |
Output is correct |
4 |
Correct |
52 ms |
98168 KB |
Output is correct |
5 |
Correct |
54 ms |
98128 KB |
Output is correct |
6 |
Correct |
56 ms |
98424 KB |
Output is correct |
7 |
Correct |
71 ms |
98388 KB |
Output is correct |
8 |
Correct |
73 ms |
98388 KB |
Output is correct |
9 |
Correct |
54 ms |
98436 KB |
Output is correct |
10 |
Correct |
166 ms |
118780 KB |
Output is correct |
11 |
Correct |
170 ms |
123248 KB |
Output is correct |
12 |
Correct |
168 ms |
122816 KB |
Output is correct |
13 |
Correct |
198 ms |
124280 KB |
Output is correct |
14 |
Correct |
137 ms |
123680 KB |
Output is correct |
15 |
Correct |
177 ms |
118972 KB |
Output is correct |
16 |
Correct |
526 ms |
127572 KB |
Output is correct |
17 |
Correct |
498 ms |
126756 KB |
Output is correct |
18 |
Correct |
486 ms |
128280 KB |
Output is correct |
19 |
Correct |
379 ms |
127136 KB |
Output is correct |
20 |
Correct |
504 ms |
123800 KB |
Output is correct |
21 |
Correct |
458 ms |
124668 KB |
Output is correct |
22 |
Correct |
520 ms |
124252 KB |
Output is correct |
23 |
Correct |
455 ms |
124500 KB |
Output is correct |
24 |
Correct |
468 ms |
124480 KB |
Output is correct |
25 |
Correct |
461 ms |
123756 KB |
Output is correct |
26 |
Correct |
468 ms |
124228 KB |
Output is correct |
27 |
Correct |
463 ms |
123524 KB |
Output is correct |
28 |
Correct |
53 ms |
98428 KB |
Output is correct |
29 |
Correct |
53 ms |
98384 KB |
Output is correct |
30 |
Correct |
55 ms |
98384 KB |
Output is correct |
31 |
Correct |
52 ms |
98384 KB |
Output is correct |
32 |
Correct |
52 ms |
98388 KB |
Output is correct |
33 |
Correct |
53 ms |
98384 KB |
Output is correct |
34 |
Correct |
53 ms |
98392 KB |
Output is correct |
35 |
Correct |
51 ms |
98372 KB |
Output is correct |
36 |
Correct |
52 ms |
98388 KB |
Output is correct |
37 |
Correct |
62 ms |
101588 KB |
Output is correct |
38 |
Correct |
158 ms |
123952 KB |
Output is correct |
39 |
Correct |
161 ms |
124068 KB |
Output is correct |
40 |
Correct |
158 ms |
124100 KB |
Output is correct |
41 |
Correct |
164 ms |
123588 KB |
Output is correct |
42 |
Correct |
174 ms |
123276 KB |
Output is correct |
43 |
Correct |
163 ms |
121000 KB |
Output is correct |
44 |
Correct |
163 ms |
124360 KB |
Output is correct |
45 |
Correct |
161 ms |
124060 KB |
Output is correct |
46 |
Correct |
131 ms |
122928 KB |
Output is correct |
47 |
Correct |
171 ms |
123592 KB |
Output is correct |
48 |
Correct |
106 ms |
101940 KB |
Output is correct |
49 |
Correct |
476 ms |
128800 KB |
Output is correct |
50 |
Correct |
509 ms |
128916 KB |
Output is correct |
51 |
Correct |
497 ms |
128808 KB |
Output is correct |
52 |
Correct |
489 ms |
128568 KB |
Output is correct |
53 |
Correct |
522 ms |
127052 KB |
Output is correct |
54 |
Correct |
489 ms |
120760 KB |
Output is correct |
55 |
Correct |
533 ms |
129876 KB |
Output is correct |
56 |
Correct |
504 ms |
128812 KB |
Output is correct |
57 |
Execution timed out |
2071 ms |
126772 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |