There are N edges , so + 1 for nodes and + 1 for 1 - based indexing
List < int > [ ] g = new List < int > [ N + 2 ] ; for ( int i = 0 ; i < g . Length ; i ++ ) g [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) addEdge ( g , edges [ i , 0 ] , edges [ i , 1 ] ) ; Console . Write ( maxProductOfTwoPaths ( g , N ) + " STRNEWLINE " ) ; } }