Using recursion formula to calculate the values of lca [ , ] , MinWeight [ , ] and MaxWeight [ , ]
lca [ node , i ] = lca [ lca [ node , i - 1 ] , i - 1 ] ; minWeight [ node , i ] = Math . Min ( minWeight [ node , i - 1 ] , minWeight [ lca [ node , i - 1 ] , i - 1 ] ) ; maxWeight [ node , i ] = Math . Max ( maxWeight [ node , i - 1 ] , maxWeight [ lca [ node , i - 1 ] , i - 1 ] ) ; } } foreach ( int i in graph [ node ] ) { if ( i == parent ) continue ; dfs ( i , node , h + 1 ) ; } }