A utility function to print the adjacency list representation of graph
function printGraph ( adj , V ) { for ( var v = 0 ; v < V ; ++ v ) { document . write ( " " + v + " " ) ; for ( var x of adj [ v ] ) document . write ( " " + x ) ; document . write ( " " ) ; } }