Number of nodes
adj = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; answer = new int [ N ] ; N = 5 ; int Edges [ ] [ ] = { { 1 , 2 } , { 1 , 3 } , { 3 , 4 } , { 3 , 5 } } ; int Val [ ] = { 0 , 2 , 3 , 4 , 8 , 16 } ; int Queries [ ] = { 2 , 3 , 1 } ; int Q = Queries . length ;