Number of nodes
adj = new List < List < int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) adj . Add ( new List < int > ( ) ) ; 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 ;