public String toString(){
  StringBuilder s=new StringBuilder();
  s.append(V + " vertices, " + E+ " edges "+ NEWLINE);
  for (int v=0; v < V; v++) {
    s.append(String.format("%d: ",v));
    for (    int w : adj[v]) {
      s.append(String.format("%d ",w));
    }
    s.append(NEWLINE);
  }
  return s.toString();
}

public String toString ( ) { StringBuilder s = new StringBuilder ( ) ; s . append ( V + " vertices, " + E + " edges " + NEWLINE ) ; for ( int v = 0 ; v < V ; v ++ ) { s . append ( String . format ( "%d: " , v ) ) ; for ( int w : adj [ v ] ) { s . append ( String . format ( "%d " , w ) ) ; } s . append ( NEWLINE ) ; } return s . toString ( ) ; }
returns a string representation of the graph .
