There are N edges , so + 1 for nodes and + 1 for 1 - based indexing
@ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] g = new Vector [ N + 2 ] ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) addEdge ( g , edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; System . out . print ( maxProductOfTwoPaths ( g , N ) + "NEW_LINE"); } }