#P440. 【例77.1】模拟链表
【例77.1】模拟链表
Description
In graph theory programming, adjacency lists are commonly used as data structures. Since dynamic pointers are slower than static arrays for access, many OI contestants use arrays to simulate pointers. Let's learn this programming method.
There are vertices, numbered from to . There are edges, each represented by the two vertices it connects, such as (, ), indicating an edge between vertices and (undirected edge). Please output the vertices adjacent to each vertex through edges.
Input Format
The first line contains two integers and , where is in the range [...] and is in the range [...]. The next lines each contain two integers representing an edge.
Output Format
lines, where the first number in the -th line indicates how many edges are connected to vertex , followed by numbers indicating which vertices are connected to vertex by an edge.
Sample
5 6
1 3
2 4
1 4
2 3
3 5
2 52 4 3
3 5 3 4
3 5 2 1
2 1 2
2 2 3