Skip to content
C

Graph Using Adjacency List

Easyjavapythonccppjavascript

Given the number of vertices V (labelled 0 .. V-1) and a list of undirected edges, build the adjacency list of the graph and print it.

Input Format

The first line contains two integers V and E. Each of the next E lines contains two integers u and v, an undirected edge.

Output Format

Print V lines. Line i is i -> [n1,n2,...] where the neighbours of vertex i are listed in increasing order, comma-separated, inside square brackets (i -> [] if it has none).

Input (stdin)

Output

Run your code to see output here...