#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
using pii=pair<int,int>;
using pli=pair<long long,int>;
const int inf=1e9+7;
const int maxn=1e5+9;
const int maxm=2e5+9;
int lab[maxn+maxm];
vector<int>a[maxn+maxm];
int deg[maxn];
int val[maxn+maxm];
bool ck[maxn+maxm];
int findset(int u){
if (lab[u]==u)return u;
return lab[u]=findset(lab[u]);
}
int nnode=0;
int n,m;
void unite(int u,int v,int w){
bool fl=false;
deg[u]++;
deg[v]++;
fl=(deg[u]>2||deg[v]>2);
u=findset(u),v=findset(v);
fl|=(ck[u]|ck[v]);
if (u==v){
ck[u]=1;
val[u]=min(val[u],w);
return;
}
nnode++;
val[nnode]=1e9+7;
a[nnode].pb(u);
a[nnode].pb(v);
lab[u]=nnode;
lab[nnode]=nnode;
lab[v]=nnode;
if (fl){
ck[nnode]=1;
val[nnode]=w;
}
return;
}
struct edg{
int u,v,w;
bool operator < (const edg &p)const {
return w<p.w;
}
};
vector<edg>b;
int st[maxn+maxm][20];
int dep[maxn+maxm];
void dfs(int u){
for (auto v:a[u]){
val[v]=min(val[v],val[u]);
st[v][0]=u;
for1(i,1,19){
st[v][i]=st[st[v][i-1]][i-1];
}
dep[v]=dep[u]+1;
dfs(v);
}
}
int lca(int u,int v){
if (dep[u]<dep[v])swap(u,v);
int k=dep[u]-dep[v];
for1(i,0,19){
if (k>>i&1)u=st[u][i];
}
if (u==v)return u;
for2(i,19,0){
if (!st[u][i]||!st[v][i])continue;
if (st[u][i]!=st[v][i]){
u=st[u][i];
v=st[v][i];
}
}
return st[u][0];
}
void init(int N,int M,vector<int>u1,vector<int>v1,vector<int>w){
n=N;
nnode=n;
m=M;
for1(i,1,n){
lab[i]=i;
val[i]=1e9+7;
}
for1(i,0,m-1){
b.pb({u1[i]+1,v1[i]+1,w[i]});
}
sort(all(b));
for (auto v:b){
unite(v.u,v.v,v.w);
}
for1(i,1,nnode){
if (val[i]==0){
val[i]=1e9+7;
}
}
dfs(nnode);
}
int getMinimumFuelCapacity(int u,int v){
int vl=val[lca(u+1,v+1)];
if (vl==inf)vl=-1;
return vl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7380 KB |
Output is correct |
3 |
Correct |
5 ms |
7300 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
5 ms |
7636 KB |
Output is correct |
6 |
Correct |
6 ms |
7512 KB |
Output is correct |
7 |
Correct |
5 ms |
7636 KB |
Output is correct |
8 |
Correct |
5 ms |
7636 KB |
Output is correct |
9 |
Correct |
100 ms |
28608 KB |
Output is correct |
10 |
Correct |
120 ms |
33416 KB |
Output is correct |
11 |
Correct |
115 ms |
33008 KB |
Output is correct |
12 |
Correct |
135 ms |
34764 KB |
Output is correct |
13 |
Correct |
104 ms |
38472 KB |
Output is correct |
14 |
Correct |
106 ms |
29000 KB |
Output is correct |
15 |
Correct |
251 ms |
37668 KB |
Output is correct |
16 |
Correct |
229 ms |
36968 KB |
Output is correct |
17 |
Correct |
250 ms |
38560 KB |
Output is correct |
18 |
Correct |
296 ms |
42532 KB |
Output is correct |
19 |
Correct |
76 ms |
16796 KB |
Output is correct |
20 |
Correct |
211 ms |
38848 KB |
Output is correct |
21 |
Correct |
212 ms |
38224 KB |
Output is correct |
22 |
Correct |
222 ms |
40008 KB |
Output is correct |
23 |
Correct |
313 ms |
43940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7380 KB |
Output is correct |
3 |
Correct |
277 ms |
45344 KB |
Output is correct |
4 |
Correct |
252 ms |
46944 KB |
Output is correct |
5 |
Correct |
291 ms |
46256 KB |
Output is correct |
6 |
Correct |
284 ms |
46800 KB |
Output is correct |
7 |
Correct |
259 ms |
46628 KB |
Output is correct |
8 |
Correct |
260 ms |
45168 KB |
Output is correct |
9 |
Correct |
320 ms |
46280 KB |
Output is correct |
10 |
Correct |
271 ms |
44820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7380 KB |
Output is correct |
3 |
Correct |
5 ms |
7300 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
5 ms |
7636 KB |
Output is correct |
6 |
Correct |
6 ms |
7512 KB |
Output is correct |
7 |
Correct |
5 ms |
7636 KB |
Output is correct |
8 |
Correct |
5 ms |
7636 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7628 KB |
Output is correct |
11 |
Correct |
4 ms |
7636 KB |
Output is correct |
12 |
Correct |
5 ms |
7636 KB |
Output is correct |
13 |
Correct |
5 ms |
7500 KB |
Output is correct |
14 |
Correct |
5 ms |
7592 KB |
Output is correct |
15 |
Correct |
5 ms |
7636 KB |
Output is correct |
16 |
Correct |
5 ms |
7636 KB |
Output is correct |
17 |
Correct |
5 ms |
7636 KB |
Output is correct |
18 |
Correct |
5 ms |
7636 KB |
Output is correct |
19 |
Correct |
5 ms |
7508 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Correct |
5 ms |
7636 KB |
Output is correct |
22 |
Correct |
6 ms |
7488 KB |
Output is correct |
23 |
Correct |
7 ms |
7536 KB |
Output is correct |
24 |
Correct |
6 ms |
7636 KB |
Output is correct |
25 |
Correct |
6 ms |
7648 KB |
Output is correct |
26 |
Correct |
6 ms |
7672 KB |
Output is correct |
27 |
Correct |
5 ms |
7636 KB |
Output is correct |
28 |
Correct |
6 ms |
7636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7300 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
5 ms |
7636 KB |
Output is correct |
7 |
Correct |
6 ms |
7512 KB |
Output is correct |
8 |
Correct |
5 ms |
7636 KB |
Output is correct |
9 |
Correct |
5 ms |
7636 KB |
Output is correct |
10 |
Correct |
100 ms |
28608 KB |
Output is correct |
11 |
Correct |
120 ms |
33416 KB |
Output is correct |
12 |
Correct |
115 ms |
33008 KB |
Output is correct |
13 |
Correct |
135 ms |
34764 KB |
Output is correct |
14 |
Correct |
104 ms |
38472 KB |
Output is correct |
15 |
Correct |
5 ms |
7628 KB |
Output is correct |
16 |
Correct |
4 ms |
7636 KB |
Output is correct |
17 |
Correct |
5 ms |
7636 KB |
Output is correct |
18 |
Correct |
5 ms |
7500 KB |
Output is correct |
19 |
Correct |
5 ms |
7592 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Correct |
5 ms |
7636 KB |
Output is correct |
22 |
Correct |
5 ms |
7636 KB |
Output is correct |
23 |
Correct |
5 ms |
7636 KB |
Output is correct |
24 |
Correct |
5 ms |
7508 KB |
Output is correct |
25 |
Correct |
5 ms |
7636 KB |
Output is correct |
26 |
Correct |
5 ms |
7636 KB |
Output is correct |
27 |
Correct |
6 ms |
7488 KB |
Output is correct |
28 |
Correct |
7 ms |
7536 KB |
Output is correct |
29 |
Correct |
6 ms |
7636 KB |
Output is correct |
30 |
Correct |
6 ms |
7648 KB |
Output is correct |
31 |
Correct |
6 ms |
7672 KB |
Output is correct |
32 |
Correct |
5 ms |
7636 KB |
Output is correct |
33 |
Correct |
6 ms |
7636 KB |
Output is correct |
34 |
Correct |
15 ms |
11032 KB |
Output is correct |
35 |
Correct |
117 ms |
34244 KB |
Output is correct |
36 |
Correct |
114 ms |
34236 KB |
Output is correct |
37 |
Correct |
118 ms |
34312 KB |
Output is correct |
38 |
Correct |
129 ms |
33964 KB |
Output is correct |
39 |
Correct |
113 ms |
33764 KB |
Output is correct |
40 |
Correct |
112 ms |
31620 KB |
Output is correct |
41 |
Correct |
132 ms |
34496 KB |
Output is correct |
42 |
Correct |
128 ms |
34328 KB |
Output is correct |
43 |
Correct |
98 ms |
39476 KB |
Output is correct |
44 |
Correct |
122 ms |
34716 KB |
Output is correct |
45 |
Correct |
128 ms |
34596 KB |
Output is correct |
46 |
Correct |
119 ms |
34236 KB |
Output is correct |
47 |
Correct |
130 ms |
34236 KB |
Output is correct |
48 |
Correct |
123 ms |
36204 KB |
Output is correct |
49 |
Correct |
70 ms |
17016 KB |
Output is correct |
50 |
Correct |
55 ms |
15676 KB |
Output is correct |
51 |
Correct |
134 ms |
29984 KB |
Output is correct |
52 |
Correct |
158 ms |
37892 KB |
Output is correct |
53 |
Correct |
157 ms |
40020 KB |
Output is correct |
54 |
Correct |
161 ms |
39900 KB |
Output is correct |
55 |
Correct |
107 ms |
38964 KB |
Output is correct |
56 |
Correct |
175 ms |
40960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7380 KB |
Output is correct |
3 |
Correct |
5 ms |
7300 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
5 ms |
7636 KB |
Output is correct |
6 |
Correct |
6 ms |
7512 KB |
Output is correct |
7 |
Correct |
5 ms |
7636 KB |
Output is correct |
8 |
Correct |
5 ms |
7636 KB |
Output is correct |
9 |
Correct |
100 ms |
28608 KB |
Output is correct |
10 |
Correct |
120 ms |
33416 KB |
Output is correct |
11 |
Correct |
115 ms |
33008 KB |
Output is correct |
12 |
Correct |
135 ms |
34764 KB |
Output is correct |
13 |
Correct |
104 ms |
38472 KB |
Output is correct |
14 |
Correct |
106 ms |
29000 KB |
Output is correct |
15 |
Correct |
251 ms |
37668 KB |
Output is correct |
16 |
Correct |
229 ms |
36968 KB |
Output is correct |
17 |
Correct |
250 ms |
38560 KB |
Output is correct |
18 |
Correct |
296 ms |
42532 KB |
Output is correct |
19 |
Correct |
277 ms |
45344 KB |
Output is correct |
20 |
Correct |
252 ms |
46944 KB |
Output is correct |
21 |
Correct |
291 ms |
46256 KB |
Output is correct |
22 |
Correct |
284 ms |
46800 KB |
Output is correct |
23 |
Correct |
259 ms |
46628 KB |
Output is correct |
24 |
Correct |
260 ms |
45168 KB |
Output is correct |
25 |
Correct |
320 ms |
46280 KB |
Output is correct |
26 |
Correct |
271 ms |
44820 KB |
Output is correct |
27 |
Correct |
5 ms |
7628 KB |
Output is correct |
28 |
Correct |
4 ms |
7636 KB |
Output is correct |
29 |
Correct |
5 ms |
7636 KB |
Output is correct |
30 |
Correct |
5 ms |
7500 KB |
Output is correct |
31 |
Correct |
5 ms |
7592 KB |
Output is correct |
32 |
Correct |
5 ms |
7636 KB |
Output is correct |
33 |
Correct |
5 ms |
7636 KB |
Output is correct |
34 |
Correct |
5 ms |
7636 KB |
Output is correct |
35 |
Correct |
5 ms |
7636 KB |
Output is correct |
36 |
Correct |
15 ms |
11032 KB |
Output is correct |
37 |
Correct |
117 ms |
34244 KB |
Output is correct |
38 |
Correct |
114 ms |
34236 KB |
Output is correct |
39 |
Correct |
118 ms |
34312 KB |
Output is correct |
40 |
Correct |
129 ms |
33964 KB |
Output is correct |
41 |
Correct |
113 ms |
33764 KB |
Output is correct |
42 |
Correct |
112 ms |
31620 KB |
Output is correct |
43 |
Correct |
132 ms |
34496 KB |
Output is correct |
44 |
Correct |
128 ms |
34328 KB |
Output is correct |
45 |
Correct |
98 ms |
39476 KB |
Output is correct |
46 |
Correct |
122 ms |
34716 KB |
Output is correct |
47 |
Correct |
22 ms |
11276 KB |
Output is correct |
48 |
Correct |
243 ms |
39108 KB |
Output is correct |
49 |
Correct |
226 ms |
39088 KB |
Output is correct |
50 |
Correct |
225 ms |
39080 KB |
Output is correct |
51 |
Correct |
226 ms |
38956 KB |
Output is correct |
52 |
Correct |
254 ms |
37512 KB |
Output is correct |
53 |
Correct |
222 ms |
31316 KB |
Output is correct |
54 |
Correct |
266 ms |
39952 KB |
Output is correct |
55 |
Correct |
245 ms |
39012 KB |
Output is correct |
56 |
Correct |
386 ms |
43304 KB |
Output is correct |
57 |
Correct |
276 ms |
40136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7300 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
5 ms |
7636 KB |
Output is correct |
7 |
Correct |
6 ms |
7512 KB |
Output is correct |
8 |
Correct |
5 ms |
7636 KB |
Output is correct |
9 |
Correct |
5 ms |
7636 KB |
Output is correct |
10 |
Correct |
100 ms |
28608 KB |
Output is correct |
11 |
Correct |
120 ms |
33416 KB |
Output is correct |
12 |
Correct |
115 ms |
33008 KB |
Output is correct |
13 |
Correct |
135 ms |
34764 KB |
Output is correct |
14 |
Correct |
104 ms |
38472 KB |
Output is correct |
15 |
Correct |
106 ms |
29000 KB |
Output is correct |
16 |
Correct |
251 ms |
37668 KB |
Output is correct |
17 |
Correct |
229 ms |
36968 KB |
Output is correct |
18 |
Correct |
250 ms |
38560 KB |
Output is correct |
19 |
Correct |
296 ms |
42532 KB |
Output is correct |
20 |
Correct |
277 ms |
45344 KB |
Output is correct |
21 |
Correct |
252 ms |
46944 KB |
Output is correct |
22 |
Correct |
291 ms |
46256 KB |
Output is correct |
23 |
Correct |
284 ms |
46800 KB |
Output is correct |
24 |
Correct |
259 ms |
46628 KB |
Output is correct |
25 |
Correct |
260 ms |
45168 KB |
Output is correct |
26 |
Correct |
320 ms |
46280 KB |
Output is correct |
27 |
Correct |
271 ms |
44820 KB |
Output is correct |
28 |
Correct |
5 ms |
7628 KB |
Output is correct |
29 |
Correct |
4 ms |
7636 KB |
Output is correct |
30 |
Correct |
5 ms |
7636 KB |
Output is correct |
31 |
Correct |
5 ms |
7500 KB |
Output is correct |
32 |
Correct |
5 ms |
7592 KB |
Output is correct |
33 |
Correct |
5 ms |
7636 KB |
Output is correct |
34 |
Correct |
5 ms |
7636 KB |
Output is correct |
35 |
Correct |
5 ms |
7636 KB |
Output is correct |
36 |
Correct |
5 ms |
7636 KB |
Output is correct |
37 |
Correct |
15 ms |
11032 KB |
Output is correct |
38 |
Correct |
117 ms |
34244 KB |
Output is correct |
39 |
Correct |
114 ms |
34236 KB |
Output is correct |
40 |
Correct |
118 ms |
34312 KB |
Output is correct |
41 |
Correct |
129 ms |
33964 KB |
Output is correct |
42 |
Correct |
113 ms |
33764 KB |
Output is correct |
43 |
Correct |
112 ms |
31620 KB |
Output is correct |
44 |
Correct |
132 ms |
34496 KB |
Output is correct |
45 |
Correct |
128 ms |
34328 KB |
Output is correct |
46 |
Correct |
98 ms |
39476 KB |
Output is correct |
47 |
Correct |
122 ms |
34716 KB |
Output is correct |
48 |
Correct |
22 ms |
11276 KB |
Output is correct |
49 |
Correct |
243 ms |
39108 KB |
Output is correct |
50 |
Correct |
226 ms |
39088 KB |
Output is correct |
51 |
Correct |
225 ms |
39080 KB |
Output is correct |
52 |
Correct |
226 ms |
38956 KB |
Output is correct |
53 |
Correct |
254 ms |
37512 KB |
Output is correct |
54 |
Correct |
222 ms |
31316 KB |
Output is correct |
55 |
Correct |
266 ms |
39952 KB |
Output is correct |
56 |
Correct |
245 ms |
39012 KB |
Output is correct |
57 |
Correct |
386 ms |
43304 KB |
Output is correct |
58 |
Correct |
276 ms |
40136 KB |
Output is correct |
59 |
Correct |
76 ms |
16796 KB |
Output is correct |
60 |
Correct |
211 ms |
38848 KB |
Output is correct |
61 |
Correct |
212 ms |
38224 KB |
Output is correct |
62 |
Correct |
222 ms |
40008 KB |
Output is correct |
63 |
Correct |
313 ms |
43940 KB |
Output is correct |
64 |
Correct |
5 ms |
7508 KB |
Output is correct |
65 |
Correct |
5 ms |
7636 KB |
Output is correct |
66 |
Correct |
5 ms |
7636 KB |
Output is correct |
67 |
Correct |
6 ms |
7488 KB |
Output is correct |
68 |
Correct |
7 ms |
7536 KB |
Output is correct |
69 |
Correct |
6 ms |
7636 KB |
Output is correct |
70 |
Correct |
6 ms |
7648 KB |
Output is correct |
71 |
Correct |
6 ms |
7672 KB |
Output is correct |
72 |
Correct |
5 ms |
7636 KB |
Output is correct |
73 |
Correct |
6 ms |
7636 KB |
Output is correct |
74 |
Correct |
128 ms |
34596 KB |
Output is correct |
75 |
Correct |
119 ms |
34236 KB |
Output is correct |
76 |
Correct |
130 ms |
34236 KB |
Output is correct |
77 |
Correct |
123 ms |
36204 KB |
Output is correct |
78 |
Correct |
70 ms |
17016 KB |
Output is correct |
79 |
Correct |
55 ms |
15676 KB |
Output is correct |
80 |
Correct |
134 ms |
29984 KB |
Output is correct |
81 |
Correct |
158 ms |
37892 KB |
Output is correct |
82 |
Correct |
157 ms |
40020 KB |
Output is correct |
83 |
Correct |
161 ms |
39900 KB |
Output is correct |
84 |
Correct |
107 ms |
38964 KB |
Output is correct |
85 |
Correct |
175 ms |
40960 KB |
Output is correct |
86 |
Correct |
88 ms |
18600 KB |
Output is correct |
87 |
Correct |
249 ms |
39092 KB |
Output is correct |
88 |
Correct |
266 ms |
39108 KB |
Output is correct |
89 |
Correct |
291 ms |
39424 KB |
Output is correct |
90 |
Correct |
178 ms |
20740 KB |
Output is correct |
91 |
Correct |
184 ms |
22628 KB |
Output is correct |
92 |
Correct |
256 ms |
34848 KB |
Output is correct |
93 |
Correct |
314 ms |
42644 KB |
Output is correct |
94 |
Correct |
335 ms |
44188 KB |
Output is correct |
95 |
Correct |
306 ms |
43740 KB |
Output is correct |
96 |
Correct |
383 ms |
43540 KB |
Output is correct |
97 |
Correct |
292 ms |
43700 KB |
Output is correct |