~/algor $ cat problems/graf-qoshnilar-royxati
Adjacency lists
Easy
1000 ms
128 MB
23%
An undirected graph with $n$ vertices and $m$ edges is given. The vertices are numbered from $1$ to $n$. For every vertex print its neighbours — the vertices joined to it by an edge — in increasing order.
Input
The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.
Output
$n$ lines: the $i$-th line contains first the number $k$ of neighbours of vertex $i$, then the $k$ neighbours in increasing order.
Note
$1 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$, $u \ne v$
There is at most one edge between any pair of vertices.
Examples
Input #1
5 5 1 2 1 3 4 1 2 3 3 5
Output #1
3 2 3 4 2 1 3 3 1 2 5 1 1 1 3
Input #2
3 0
Output #2
0 0 0