Initializing graph in the form of adjacency list
@ SuppressWarnings ( " unchecked " ) List < List < Integer > > graph = new ArrayList ( ) ; for ( int i = 0 ; i < 1001 ; i ++ ) graph . add ( new ArrayList < Integer > ( ) ) ;