#include<bits/stdc++.h>
#include "swap.h"
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t)){
cerr<<", ";
}
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int K=18, N=3e5+5;
int r[N], par[K][N], tim[N], czy[N], deg[N], nxt[N], dep[N];
int find(int v){
if(r[v]==v)return v;
return r[v]=find(r[v]);
}
void init(int n, int m, std::vector<int> uu, std::vector<int> vv, std::vector<int> ww) {
vector<pair<int, pii> > edg;
for(int i=0; i<m; i++){
edg.eb(ww[i], mp(uu[i], vv[i]));
}
sort(all(edg));
for(int i=0; i<N; i++){
r[i]=i;
}
int wsk=n;
for(int ii=0; ii<m; ii++){
int u=edg[ii].nd.st, v=edg[ii].nd.nd, w=edg[ii].st;
deg[u]++;
deg[v]++;
bool b=(deg[u]>=3||deg[v]>=3);
u=find(u);
v=find(v);
if(u==v && !czy[u]){
par[0][u]=r[u]=wsk;
tim[wsk]=w;
czy[wsk]=1;
wsk++;
}
if(u!=v){
par[0][u]=r[u]=wsk;
par[0][v]=r[v]=wsk;
tim[wsk]=w;
czy[wsk]=(b||czy[u]||czy[v]);
wsk++;
}
}
par[0][wsk-1]=wsk-1;
for(int k=1; k<K; k++){
for(int i=0; i<wsk; i++){
par[k][i]=par[k-1][par[k-1][i]];
}
}
for(int i=wsk-1; i>=0; i--){
if(czy[i])nxt[i]=tim[i];
else{
if(par[0][i]==i)nxt[i]=1e9+5;
else nxt[i]=nxt[par[0][i]];
}
if(par[0][i]!=i)dep[i]=dep[par[0][i]]+1;
}
for(int i=0; i<wsk; i++){
//deb(i, par[0][i], czy[i], tim[i], nxt[i], dep[i]);
}
}
int lca(int u, int v){
if(dep[u]>dep[v])swap(u, v);
for(int i=K-1; i>=0; i--){
if(dep[u]+(1<<i)<=dep[v])v=par[i][v];
}
if(u==v)return u;
for(int i=K-1; i>=0; i--){
if(par[i][v]!=par[i][u]){
v=par[i][v];
u=par[i][u];
}
}
return par[0][u];
}
int getMinimumFuelCapacity(int X, int Y) {
if(X==Y)return 0;
int Z=lca(X, Y);
if(nxt[Z]==1e9+5)return -1;
else return nxt[Z];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1596 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
34 ms |
19280 KB |
Output is correct |
10 |
Correct |
53 ms |
23164 KB |
Output is correct |
11 |
Correct |
40 ms |
22908 KB |
Output is correct |
12 |
Correct |
43 ms |
24112 KB |
Output is correct |
13 |
Correct |
42 ms |
24764 KB |
Output is correct |
14 |
Correct |
42 ms |
19660 KB |
Output is correct |
15 |
Correct |
140 ms |
27312 KB |
Output is correct |
16 |
Correct |
141 ms |
26632 KB |
Output is correct |
17 |
Correct |
158 ms |
28016 KB |
Output is correct |
18 |
Correct |
229 ms |
28640 KB |
Output is correct |
19 |
Correct |
60 ms |
10204 KB |
Output is correct |
20 |
Correct |
189 ms |
27300 KB |
Output is correct |
21 |
Correct |
149 ms |
26976 KB |
Output is correct |
22 |
Correct |
139 ms |
28296 KB |
Output is correct |
23 |
Correct |
192 ms |
28936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
181 ms |
26476 KB |
Output is correct |
4 |
Correct |
159 ms |
27380 KB |
Output is correct |
5 |
Correct |
188 ms |
27176 KB |
Output is correct |
6 |
Correct |
180 ms |
27280 KB |
Output is correct |
7 |
Correct |
165 ms |
27324 KB |
Output is correct |
8 |
Correct |
158 ms |
26480 KB |
Output is correct |
9 |
Correct |
186 ms |
27012 KB |
Output is correct |
10 |
Correct |
172 ms |
26320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1596 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
2 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1736 KB |
Output is correct |
14 |
Correct |
1 ms |
1748 KB |
Output is correct |
15 |
Correct |
1 ms |
1748 KB |
Output is correct |
16 |
Correct |
1 ms |
1728 KB |
Output is correct |
17 |
Correct |
1 ms |
1748 KB |
Output is correct |
18 |
Correct |
2 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1748 KB |
Output is correct |
20 |
Correct |
1 ms |
1748 KB |
Output is correct |
21 |
Correct |
1 ms |
1732 KB |
Output is correct |
22 |
Correct |
2 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1748 KB |
Output is correct |
24 |
Correct |
2 ms |
1876 KB |
Output is correct |
25 |
Correct |
2 ms |
1900 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Correct |
1 ms |
1596 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
34 ms |
19280 KB |
Output is correct |
11 |
Correct |
53 ms |
23164 KB |
Output is correct |
12 |
Correct |
40 ms |
22908 KB |
Output is correct |
13 |
Correct |
43 ms |
24112 KB |
Output is correct |
14 |
Correct |
42 ms |
24764 KB |
Output is correct |
15 |
Correct |
1 ms |
1748 KB |
Output is correct |
16 |
Correct |
1 ms |
1748 KB |
Output is correct |
17 |
Correct |
2 ms |
1748 KB |
Output is correct |
18 |
Correct |
1 ms |
1736 KB |
Output is correct |
19 |
Correct |
1 ms |
1748 KB |
Output is correct |
20 |
Correct |
1 ms |
1748 KB |
Output is correct |
21 |
Correct |
1 ms |
1728 KB |
Output is correct |
22 |
Correct |
1 ms |
1748 KB |
Output is correct |
23 |
Correct |
2 ms |
1748 KB |
Output is correct |
24 |
Correct |
1 ms |
1748 KB |
Output is correct |
25 |
Correct |
1 ms |
1748 KB |
Output is correct |
26 |
Correct |
1 ms |
1732 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
1 ms |
1748 KB |
Output is correct |
29 |
Correct |
2 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1900 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
2 ms |
1748 KB |
Output is correct |
33 |
Correct |
1 ms |
1876 KB |
Output is correct |
34 |
Correct |
9 ms |
4756 KB |
Output is correct |
35 |
Correct |
55 ms |
23888 KB |
Output is correct |
36 |
Correct |
50 ms |
23848 KB |
Output is correct |
37 |
Correct |
41 ms |
23868 KB |
Output is correct |
38 |
Correct |
41 ms |
23472 KB |
Output is correct |
39 |
Correct |
40 ms |
23356 KB |
Output is correct |
40 |
Correct |
37 ms |
21568 KB |
Output is correct |
41 |
Correct |
42 ms |
24112 KB |
Output is correct |
42 |
Correct |
41 ms |
23872 KB |
Output is correct |
43 |
Correct |
40 ms |
23868 KB |
Output is correct |
44 |
Correct |
42 ms |
24144 KB |
Output is correct |
45 |
Correct |
63 ms |
23196 KB |
Output is correct |
46 |
Correct |
40 ms |
23872 KB |
Output is correct |
47 |
Correct |
45 ms |
23744 KB |
Output is correct |
48 |
Correct |
50 ms |
24004 KB |
Output is correct |
49 |
Correct |
51 ms |
10172 KB |
Output is correct |
50 |
Correct |
38 ms |
9440 KB |
Output is correct |
51 |
Correct |
53 ms |
19604 KB |
Output is correct |
52 |
Correct |
64 ms |
27596 KB |
Output is correct |
53 |
Correct |
74 ms |
31444 KB |
Output is correct |
54 |
Correct |
85 ms |
29492 KB |
Output is correct |
55 |
Correct |
41 ms |
23816 KB |
Output is correct |
56 |
Correct |
73 ms |
28184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1596 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
34 ms |
19280 KB |
Output is correct |
10 |
Correct |
53 ms |
23164 KB |
Output is correct |
11 |
Correct |
40 ms |
22908 KB |
Output is correct |
12 |
Correct |
43 ms |
24112 KB |
Output is correct |
13 |
Correct |
42 ms |
24764 KB |
Output is correct |
14 |
Correct |
42 ms |
19660 KB |
Output is correct |
15 |
Correct |
140 ms |
27312 KB |
Output is correct |
16 |
Correct |
141 ms |
26632 KB |
Output is correct |
17 |
Correct |
158 ms |
28016 KB |
Output is correct |
18 |
Correct |
229 ms |
28640 KB |
Output is correct |
19 |
Correct |
181 ms |
26476 KB |
Output is correct |
20 |
Correct |
159 ms |
27380 KB |
Output is correct |
21 |
Correct |
188 ms |
27176 KB |
Output is correct |
22 |
Correct |
180 ms |
27280 KB |
Output is correct |
23 |
Correct |
165 ms |
27324 KB |
Output is correct |
24 |
Correct |
158 ms |
26480 KB |
Output is correct |
25 |
Correct |
186 ms |
27012 KB |
Output is correct |
26 |
Correct |
172 ms |
26320 KB |
Output is correct |
27 |
Correct |
1 ms |
1748 KB |
Output is correct |
28 |
Correct |
1 ms |
1748 KB |
Output is correct |
29 |
Correct |
2 ms |
1748 KB |
Output is correct |
30 |
Correct |
1 ms |
1736 KB |
Output is correct |
31 |
Correct |
1 ms |
1748 KB |
Output is correct |
32 |
Correct |
1 ms |
1748 KB |
Output is correct |
33 |
Correct |
1 ms |
1728 KB |
Output is correct |
34 |
Correct |
1 ms |
1748 KB |
Output is correct |
35 |
Correct |
2 ms |
1748 KB |
Output is correct |
36 |
Correct |
9 ms |
4756 KB |
Output is correct |
37 |
Correct |
55 ms |
23888 KB |
Output is correct |
38 |
Correct |
50 ms |
23848 KB |
Output is correct |
39 |
Correct |
41 ms |
23868 KB |
Output is correct |
40 |
Correct |
41 ms |
23472 KB |
Output is correct |
41 |
Correct |
40 ms |
23356 KB |
Output is correct |
42 |
Correct |
37 ms |
21568 KB |
Output is correct |
43 |
Correct |
42 ms |
24112 KB |
Output is correct |
44 |
Correct |
41 ms |
23872 KB |
Output is correct |
45 |
Correct |
40 ms |
23868 KB |
Output is correct |
46 |
Correct |
42 ms |
24144 KB |
Output is correct |
47 |
Correct |
13 ms |
4820 KB |
Output is correct |
48 |
Correct |
162 ms |
27720 KB |
Output is correct |
49 |
Correct |
143 ms |
27740 KB |
Output is correct |
50 |
Correct |
176 ms |
27708 KB |
Output is correct |
51 |
Correct |
125 ms |
27472 KB |
Output is correct |
52 |
Correct |
119 ms |
26260 KB |
Output is correct |
53 |
Correct |
141 ms |
21436 KB |
Output is correct |
54 |
Correct |
159 ms |
28300 KB |
Output is correct |
55 |
Correct |
138 ms |
27664 KB |
Output is correct |
56 |
Correct |
182 ms |
27716 KB |
Output is correct |
57 |
Correct |
133 ms |
28360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Correct |
1 ms |
1596 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
34 ms |
19280 KB |
Output is correct |
11 |
Correct |
53 ms |
23164 KB |
Output is correct |
12 |
Correct |
40 ms |
22908 KB |
Output is correct |
13 |
Correct |
43 ms |
24112 KB |
Output is correct |
14 |
Correct |
42 ms |
24764 KB |
Output is correct |
15 |
Correct |
42 ms |
19660 KB |
Output is correct |
16 |
Correct |
140 ms |
27312 KB |
Output is correct |
17 |
Correct |
141 ms |
26632 KB |
Output is correct |
18 |
Correct |
158 ms |
28016 KB |
Output is correct |
19 |
Correct |
229 ms |
28640 KB |
Output is correct |
20 |
Correct |
181 ms |
26476 KB |
Output is correct |
21 |
Correct |
159 ms |
27380 KB |
Output is correct |
22 |
Correct |
188 ms |
27176 KB |
Output is correct |
23 |
Correct |
180 ms |
27280 KB |
Output is correct |
24 |
Correct |
165 ms |
27324 KB |
Output is correct |
25 |
Correct |
158 ms |
26480 KB |
Output is correct |
26 |
Correct |
186 ms |
27012 KB |
Output is correct |
27 |
Correct |
172 ms |
26320 KB |
Output is correct |
28 |
Correct |
1 ms |
1748 KB |
Output is correct |
29 |
Correct |
1 ms |
1748 KB |
Output is correct |
30 |
Correct |
2 ms |
1748 KB |
Output is correct |
31 |
Correct |
1 ms |
1736 KB |
Output is correct |
32 |
Correct |
1 ms |
1748 KB |
Output is correct |
33 |
Correct |
1 ms |
1748 KB |
Output is correct |
34 |
Correct |
1 ms |
1728 KB |
Output is correct |
35 |
Correct |
1 ms |
1748 KB |
Output is correct |
36 |
Correct |
2 ms |
1748 KB |
Output is correct |
37 |
Correct |
9 ms |
4756 KB |
Output is correct |
38 |
Correct |
55 ms |
23888 KB |
Output is correct |
39 |
Correct |
50 ms |
23848 KB |
Output is correct |
40 |
Correct |
41 ms |
23868 KB |
Output is correct |
41 |
Correct |
41 ms |
23472 KB |
Output is correct |
42 |
Correct |
40 ms |
23356 KB |
Output is correct |
43 |
Correct |
37 ms |
21568 KB |
Output is correct |
44 |
Correct |
42 ms |
24112 KB |
Output is correct |
45 |
Correct |
41 ms |
23872 KB |
Output is correct |
46 |
Correct |
40 ms |
23868 KB |
Output is correct |
47 |
Correct |
42 ms |
24144 KB |
Output is correct |
48 |
Correct |
13 ms |
4820 KB |
Output is correct |
49 |
Correct |
162 ms |
27720 KB |
Output is correct |
50 |
Correct |
143 ms |
27740 KB |
Output is correct |
51 |
Correct |
176 ms |
27708 KB |
Output is correct |
52 |
Correct |
125 ms |
27472 KB |
Output is correct |
53 |
Correct |
119 ms |
26260 KB |
Output is correct |
54 |
Correct |
141 ms |
21436 KB |
Output is correct |
55 |
Correct |
159 ms |
28300 KB |
Output is correct |
56 |
Correct |
138 ms |
27664 KB |
Output is correct |
57 |
Correct |
182 ms |
27716 KB |
Output is correct |
58 |
Correct |
133 ms |
28360 KB |
Output is correct |
59 |
Correct |
60 ms |
10204 KB |
Output is correct |
60 |
Correct |
189 ms |
27300 KB |
Output is correct |
61 |
Correct |
149 ms |
26976 KB |
Output is correct |
62 |
Correct |
139 ms |
28296 KB |
Output is correct |
63 |
Correct |
192 ms |
28936 KB |
Output is correct |
64 |
Correct |
1 ms |
1748 KB |
Output is correct |
65 |
Correct |
1 ms |
1748 KB |
Output is correct |
66 |
Correct |
1 ms |
1732 KB |
Output is correct |
67 |
Correct |
2 ms |
1748 KB |
Output is correct |
68 |
Correct |
1 ms |
1748 KB |
Output is correct |
69 |
Correct |
2 ms |
1876 KB |
Output is correct |
70 |
Correct |
2 ms |
1900 KB |
Output is correct |
71 |
Correct |
1 ms |
1876 KB |
Output is correct |
72 |
Correct |
2 ms |
1748 KB |
Output is correct |
73 |
Correct |
1 ms |
1876 KB |
Output is correct |
74 |
Correct |
63 ms |
23196 KB |
Output is correct |
75 |
Correct |
40 ms |
23872 KB |
Output is correct |
76 |
Correct |
45 ms |
23744 KB |
Output is correct |
77 |
Correct |
50 ms |
24004 KB |
Output is correct |
78 |
Correct |
51 ms |
10172 KB |
Output is correct |
79 |
Correct |
38 ms |
9440 KB |
Output is correct |
80 |
Correct |
53 ms |
19604 KB |
Output is correct |
81 |
Correct |
64 ms |
27596 KB |
Output is correct |
82 |
Correct |
74 ms |
31444 KB |
Output is correct |
83 |
Correct |
85 ms |
29492 KB |
Output is correct |
84 |
Correct |
41 ms |
23816 KB |
Output is correct |
85 |
Correct |
73 ms |
28184 KB |
Output is correct |
86 |
Correct |
42 ms |
10612 KB |
Output is correct |
87 |
Correct |
124 ms |
27788 KB |
Output is correct |
88 |
Correct |
135 ms |
27696 KB |
Output is correct |
89 |
Correct |
158 ms |
26488 KB |
Output is correct |
90 |
Correct |
116 ms |
14152 KB |
Output is correct |
91 |
Correct |
122 ms |
15292 KB |
Output is correct |
92 |
Correct |
163 ms |
23232 KB |
Output is correct |
93 |
Correct |
147 ms |
31396 KB |
Output is correct |
94 |
Correct |
157 ms |
34488 KB |
Output is correct |
95 |
Correct |
168 ms |
33444 KB |
Output is correct |
96 |
Correct |
221 ms |
27736 KB |
Output is correct |
97 |
Correct |
165 ms |
30008 KB |
Output is correct |