#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll,ll> pl;
#define pb push_back
#define ff first
#define ss second
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,m,mid,mn,T,sum,h1,h2,x,y,z,l,r,cnt,cnt1,ans;
vector<pair<ll,pl>> edge;
bool ok,ok1;
vector<int> par,path,sz,w,mx,lvl,c;
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
for(int i=0;i<M;i++){
edge.pb({W[i],{U[i],V[i]}});
}
n=N;
par.resize(n);
path.resize(n);
sz.resize(n);
mx.resize(n);
lvl.resize(n);
c.resize(n);
sort(edge.begin(),edge.end());
}
int dsu(ll x){
return par[x] = (par[x] == x ? x : dsu(par[x]));
}
void connect(ll x,ll y){
x=dsu(x);
y=dsu(y);
if(x==y){
return;
}
else{
if(lvl[x]>=lvl[y]){
par[y]=x;
mx[x]=max(mx[x],mx[y]);
sz[x]+=sz[y];
path[x]+=path[y];
}
else{
par[x]=y;
mx[y]=max(mx[x],mx[y]);
sz[y]+=sz[x];
path[y]+=path[x];
}
}
}
void run(){
for(int i=0;i<n;i++){
par[i]=i;
}
for(int i=0;i<n;i++){
c[i]=0;
path[i]=0;
sz[i]=1;
mx[i]=0;
lvl[i]=0;
}
}
int getMinimumFuelCapacity(int X, int Y) {
run();
for(auto u:edge){
x=u.ss.ff;
y=u.ss.ss;
connect(x,y);
c[x]++;
c[y]++;
path[dsu(x)]++;
mx[dsu(x)] = max(mx[dsu(x)],c[x]);
mx[dsu(y)] = max(mx[dsu(y)],c[y]);
if(dsu(X)!=dsu(Y))continue;
if(mx[dsu(X)]<3&&path[dsu(X)]<sz[dsu(X)])continue;
return u.ff;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
56 ms |
4796 KB |
Output is correct |
10 |
Correct |
95 ms |
5932 KB |
Output is correct |
11 |
Correct |
104 ms |
5880 KB |
Output is correct |
12 |
Correct |
111 ms |
6164 KB |
Output is correct |
13 |
Correct |
106 ms |
6164 KB |
Output is correct |
14 |
Execution timed out |
2083 ms |
5052 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2083 ms |
7292 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
56 ms |
4796 KB |
Output is correct |
11 |
Correct |
95 ms |
5932 KB |
Output is correct |
12 |
Correct |
104 ms |
5880 KB |
Output is correct |
13 |
Correct |
111 ms |
6164 KB |
Output is correct |
14 |
Correct |
106 ms |
6164 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
8 ms |
1292 KB |
Output is correct |
35 |
Correct |
108 ms |
7964 KB |
Output is correct |
36 |
Correct |
108 ms |
7864 KB |
Output is correct |
37 |
Correct |
112 ms |
7952 KB |
Output is correct |
38 |
Correct |
111 ms |
7832 KB |
Output is correct |
39 |
Correct |
109 ms |
7736 KB |
Output is correct |
40 |
Correct |
104 ms |
7084 KB |
Output is correct |
41 |
Correct |
114 ms |
8232 KB |
Output is correct |
42 |
Correct |
113 ms |
7960 KB |
Output is correct |
43 |
Correct |
81 ms |
7864 KB |
Output is correct |
44 |
Correct |
117 ms |
8228 KB |
Output is correct |
45 |
Correct |
130 ms |
9652 KB |
Output is correct |
46 |
Correct |
117 ms |
7960 KB |
Output is correct |
47 |
Correct |
112 ms |
7920 KB |
Output is correct |
48 |
Correct |
111 ms |
8480 KB |
Output is correct |
49 |
Correct |
71 ms |
9612 KB |
Output is correct |
50 |
Correct |
62 ms |
6972 KB |
Output is correct |
51 |
Correct |
100 ms |
8644 KB |
Output is correct |
52 |
Correct |
141 ms |
10736 KB |
Output is correct |
53 |
Correct |
142 ms |
11544 KB |
Output is correct |
54 |
Correct |
161 ms |
12444 KB |
Output is correct |
55 |
Correct |
88 ms |
7980 KB |
Output is correct |
56 |
Correct |
178 ms |
11056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
56 ms |
4796 KB |
Output is correct |
10 |
Correct |
95 ms |
5932 KB |
Output is correct |
11 |
Correct |
104 ms |
5880 KB |
Output is correct |
12 |
Correct |
111 ms |
6164 KB |
Output is correct |
13 |
Correct |
106 ms |
6164 KB |
Output is correct |
14 |
Execution timed out |
2083 ms |
5052 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
56 ms |
4796 KB |
Output is correct |
11 |
Correct |
95 ms |
5932 KB |
Output is correct |
12 |
Correct |
104 ms |
5880 KB |
Output is correct |
13 |
Correct |
111 ms |
6164 KB |
Output is correct |
14 |
Correct |
106 ms |
6164 KB |
Output is correct |
15 |
Execution timed out |
2083 ms |
5052 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |