Creating Adjacency list
private static List < List < int > > constructTree ( int n , int [ , ] edges ) { List < List < int > > adjl = new List < List < int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { adjl . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < edges . GetLength ( 0 ) ; i ++ ) { int u = edges [ i , 0 ] ; int v = edges [ i , 1 ] ; adjl [ u ] . Add ( v ) ; adjl [ v ] . Add ( u ) ; } return adjl ; }