File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,7 @@ impl Dsu {
134
134
/// - $O(\alpha(n))$ amortized
135
135
pub fn leader ( & mut self , a : usize ) -> usize {
136
136
assert ! ( a < self . n) ;
137
- if self . parent_or_size [ a] < 0 {
138
- return a;
139
- }
140
- self . parent_or_size [ a] = self . leader ( self . parent_or_size [ a] as usize ) as i32 ;
141
- self . parent_or_size [ a] as usize
137
+ self . _leader ( a)
142
138
}
143
139
144
140
/// Returns the size of the connected component that contains the vertex $a$.
@@ -186,6 +182,14 @@ impl Dsu {
186
182
. filter ( |x| !x. is_empty ( ) )
187
183
. collect :: < Vec < Vec < usize > > > ( )
188
184
}
185
+
186
+ fn _leader ( & mut self , a : usize ) -> usize {
187
+ if self . parent_or_size [ a] < 0 {
188
+ return a;
189
+ }
190
+ self . parent_or_size [ a] = self . _leader ( self . parent_or_size [ a] as usize ) as i32 ;
191
+ self . parent_or_size [ a] as usize
192
+ }
189
193
}
190
194
191
195
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments