Numbers to node
int [ ] tree = new int [ n + 1 ] ; tree [ 1 ] = 10 ; tree [ 2 ] = 5 ; tree [ 3 ] = 11 ; tree [ 4 ] = 6 ; tree [ 5 ] = 8 ; int [ ] dp1 = new int [ n + 1 ] ; int [ ] dp2 = new int [ n + 1 ] ; Array . Fill ( dp1 , 0 ) ; Array . Fill ( dp2 , 0 ) ; dfs ( 1 , 1 , dp1 , dp2 , adj , tree ) ;