#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
struct yal{
int u,v,w,vas;
bool operator <(yal b){
return w<b.w;
}
int getad(int fu){
return (fu^u^v);
}
};
const int maxn=100000+10,lg=17;
int n,m,wlca[lg][maxn],inf=1e9+5,mainres[maxn];
vector<yal>alle;
vector<int>adjt[maxn];
struct dsu{
int par[maxn],val[maxn];
vector<int>allv[maxn];
dsu(){
for(int i=0;i<maxn;i++){
par[i]=i;
val[i]=inf;
allv[i].push_back(i);
}
};
int root(int u){
if(u==par[u]){
return u;
}
return par[u]=root(par[u]);
}
int con(int u,int v,int w){
int rootu=root(u),rootv=root(v);
if(rootu!=rootv){
par[rootv]=rootu;
if((int)allv[rootu].size()<(int)allv[rootv].size()){
swap(allv[rootu],allv[rootv]);
}
for(auto x:allv[rootv]){
allv[rootu].push_back(x);
}
if(val[rootu]<inf||val[rootv]<inf){
val[rootu]=w;
}
if(val[rootu]<inf){
for(auto x:allv[rootu]){
mainres[x]=min(mainres[x],val[rootu]);
}
allv[rootu].clear();
}
return 1;
}else{
return 0;
}
}
void tagh(int u,int w){
u=root(u);
for(auto x:allv[u]){
mainres[x]=min(mainres[x],w);
}
allv[u].clear();
val[u]=min(w,val[u]);
}
}ds;
int av=inf;
void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N;
m=M;
alle.resize(m);
for(int i=0;i<maxn;i++){
mainres[i]=inf;
}
for(int i=0;i<m;i++){
alle[i].u=U[i];
alle[i].v=V[i];
alle[i].w=W[i];
}
sort(alle.begin(),alle.end());
for(int i=0;i<m;i++){
if(ds.con(alle[i].u,alle[i].v,alle[i].w)){
alle[i].vas=1;
adjt[alle[i].u].push_back(i);
adjt[alle[i].v].push_back(i);
if((int)adjt[alle[i].u].size()>2||(int)adjt[alle[i].v].size()>2){
ds.tagh(alle[i].u,alle[i].w);
}
}else{
ds.tagh(alle[i].u,alle[i].w);
}
}
}
int mx;
void dfsres(int u,int had,int par=-1,int len=0){
if(had==u){
mx=len;
return ;
}
for(auto x:adjt[u]){
int v=alle[x].getad(u);
if(v==par){
continue;
}
dfsres(v,had,u,max(len,alle[x].w));
}
}
int getMinimumFuelCapacity(int X, int Y) {
mx=inf;
dfsres(X,Y);
long long ret=max(mx,min(mainres[X],mainres[Y]));
if(ret>=inf){
return -1;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9912 KB |
Output is correct |
3 |
Correct |
6 ms |
9660 KB |
Output is correct |
4 |
Correct |
6 ms |
9820 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
7 ms |
10076 KB |
Output is correct |
7 |
Correct |
6 ms |
9920 KB |
Output is correct |
8 |
Correct |
6 ms |
9820 KB |
Output is correct |
9 |
Correct |
60 ms |
20448 KB |
Output is correct |
10 |
Correct |
97 ms |
24736 KB |
Output is correct |
11 |
Correct |
101 ms |
24348 KB |
Output is correct |
12 |
Correct |
117 ms |
25320 KB |
Output is correct |
13 |
Correct |
69 ms |
22420 KB |
Output is correct |
14 |
Execution timed out |
2036 ms |
23080 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9912 KB |
Output is correct |
3 |
Execution timed out |
2063 ms |
18268 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9912 KB |
Output is correct |
3 |
Correct |
6 ms |
9660 KB |
Output is correct |
4 |
Correct |
6 ms |
9820 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
7 ms |
10076 KB |
Output is correct |
7 |
Correct |
6 ms |
9920 KB |
Output is correct |
8 |
Correct |
6 ms |
9820 KB |
Output is correct |
9 |
Correct |
5 ms |
9820 KB |
Output is correct |
10 |
Correct |
6 ms |
9828 KB |
Output is correct |
11 |
Correct |
6 ms |
9820 KB |
Output is correct |
12 |
Correct |
7 ms |
9820 KB |
Output is correct |
13 |
Correct |
6 ms |
9820 KB |
Output is correct |
14 |
Correct |
7 ms |
9824 KB |
Output is correct |
15 |
Correct |
6 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
9820 KB |
Output is correct |
17 |
Correct |
6 ms |
9820 KB |
Output is correct |
18 |
Correct |
6 ms |
9980 KB |
Output is correct |
19 |
Correct |
5 ms |
9820 KB |
Output is correct |
20 |
Correct |
6 ms |
9916 KB |
Output is correct |
21 |
Correct |
6 ms |
9820 KB |
Output is correct |
22 |
Correct |
6 ms |
9820 KB |
Output is correct |
23 |
Correct |
6 ms |
9820 KB |
Output is correct |
24 |
Correct |
6 ms |
10076 KB |
Output is correct |
25 |
Correct |
7 ms |
9820 KB |
Output is correct |
26 |
Correct |
7 ms |
10076 KB |
Output is correct |
27 |
Correct |
6 ms |
9820 KB |
Output is correct |
28 |
Correct |
7 ms |
9820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
6 ms |
9912 KB |
Output is correct |
4 |
Correct |
6 ms |
9660 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
6 ms |
9820 KB |
Output is correct |
7 |
Correct |
7 ms |
10076 KB |
Output is correct |
8 |
Correct |
6 ms |
9920 KB |
Output is correct |
9 |
Correct |
6 ms |
9820 KB |
Output is correct |
10 |
Correct |
60 ms |
20448 KB |
Output is correct |
11 |
Correct |
97 ms |
24736 KB |
Output is correct |
12 |
Correct |
101 ms |
24348 KB |
Output is correct |
13 |
Correct |
117 ms |
25320 KB |
Output is correct |
14 |
Correct |
69 ms |
22420 KB |
Output is correct |
15 |
Correct |
6 ms |
9828 KB |
Output is correct |
16 |
Correct |
6 ms |
9820 KB |
Output is correct |
17 |
Correct |
7 ms |
9820 KB |
Output is correct |
18 |
Correct |
6 ms |
9820 KB |
Output is correct |
19 |
Correct |
7 ms |
9824 KB |
Output is correct |
20 |
Correct |
6 ms |
9820 KB |
Output is correct |
21 |
Correct |
5 ms |
9820 KB |
Output is correct |
22 |
Correct |
6 ms |
9820 KB |
Output is correct |
23 |
Correct |
6 ms |
9980 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
6 ms |
9916 KB |
Output is correct |
26 |
Correct |
6 ms |
9820 KB |
Output is correct |
27 |
Correct |
6 ms |
9820 KB |
Output is correct |
28 |
Correct |
6 ms |
9820 KB |
Output is correct |
29 |
Correct |
6 ms |
10076 KB |
Output is correct |
30 |
Correct |
7 ms |
9820 KB |
Output is correct |
31 |
Correct |
7 ms |
10076 KB |
Output is correct |
32 |
Correct |
6 ms |
9820 KB |
Output is correct |
33 |
Correct |
7 ms |
9820 KB |
Output is correct |
34 |
Correct |
12 ms |
11072 KB |
Output is correct |
35 |
Correct |
100 ms |
25020 KB |
Output is correct |
36 |
Correct |
101 ms |
22968 KB |
Output is correct |
37 |
Correct |
103 ms |
20028 KB |
Output is correct |
38 |
Correct |
90 ms |
19280 KB |
Output is correct |
39 |
Correct |
84 ms |
18772 KB |
Output is correct |
40 |
Correct |
75 ms |
18004 KB |
Output is correct |
41 |
Correct |
104 ms |
24824 KB |
Output is correct |
42 |
Correct |
98 ms |
23980 KB |
Output is correct |
43 |
Correct |
70 ms |
22728 KB |
Output is correct |
44 |
Correct |
84 ms |
19024 KB |
Output is correct |
45 |
Correct |
87 ms |
21076 KB |
Output is correct |
46 |
Correct |
98 ms |
22712 KB |
Output is correct |
47 |
Correct |
94 ms |
19280 KB |
Output is correct |
48 |
Correct |
85 ms |
19280 KB |
Output is correct |
49 |
Correct |
52 ms |
18792 KB |
Output is correct |
50 |
Correct |
45 ms |
16980 KB |
Output is correct |
51 |
Correct |
73 ms |
19676 KB |
Output is correct |
52 |
Correct |
115 ms |
25412 KB |
Output is correct |
53 |
Correct |
100 ms |
23632 KB |
Output is correct |
54 |
Correct |
132 ms |
29452 KB |
Output is correct |
55 |
Correct |
75 ms |
23484 KB |
Output is correct |
56 |
Correct |
143 ms |
23340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
6 ms |
9912 KB |
Output is correct |
3 |
Correct |
6 ms |
9660 KB |
Output is correct |
4 |
Correct |
6 ms |
9820 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
7 ms |
10076 KB |
Output is correct |
7 |
Correct |
6 ms |
9920 KB |
Output is correct |
8 |
Correct |
6 ms |
9820 KB |
Output is correct |
9 |
Correct |
60 ms |
20448 KB |
Output is correct |
10 |
Correct |
97 ms |
24736 KB |
Output is correct |
11 |
Correct |
101 ms |
24348 KB |
Output is correct |
12 |
Correct |
117 ms |
25320 KB |
Output is correct |
13 |
Correct |
69 ms |
22420 KB |
Output is correct |
14 |
Execution timed out |
2036 ms |
23080 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9820 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
6 ms |
9912 KB |
Output is correct |
4 |
Correct |
6 ms |
9660 KB |
Output is correct |
5 |
Correct |
6 ms |
9820 KB |
Output is correct |
6 |
Correct |
6 ms |
9820 KB |
Output is correct |
7 |
Correct |
7 ms |
10076 KB |
Output is correct |
8 |
Correct |
6 ms |
9920 KB |
Output is correct |
9 |
Correct |
6 ms |
9820 KB |
Output is correct |
10 |
Correct |
60 ms |
20448 KB |
Output is correct |
11 |
Correct |
97 ms |
24736 KB |
Output is correct |
12 |
Correct |
101 ms |
24348 KB |
Output is correct |
13 |
Correct |
117 ms |
25320 KB |
Output is correct |
14 |
Correct |
69 ms |
22420 KB |
Output is correct |
15 |
Execution timed out |
2036 ms |
23080 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |