#abc276b. B - Adjacency List

B - Adjacency List

Score : 200200 points

问题描述

NN 座编号为 1,,N1, \dots, N 的城市,以及 MM 条连接这些城市的道路。
ii 条道路 (1iM)(1 \leq i \leq M) 连接城市 AiA_i 和城市 BiB_i

按以下方式打印出 NN 行内容:

  • did_i 表示与城市 i(1iN)i \, (1 \leq i \leq N) 直接相连的城市数量,这些城市依次为城市 ai,1a_{i, 1}\dots、城市 ai,dia_{i, d_i},并按照 升序 排列。
  • ii(1iN)(1 \leq i \leq N) 应包含 di+1d_i + 1 个整数,按照 di,ai,1,,ai,did_i, a_{i, 1}, \dots, a_{i, d_i} 的顺序排列,并用空格隔开。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN cities numbered 1,,N1, \dots, N, and MM roads connecting cities.
The ii-th road (1iM)(1 \leq i \leq M) connects city AiA_i and city BiB_i.

Print NN lines as follows.

  • Let did_i be the number of cities directly connected to city i(1iN)i \, (1 \leq i \leq N), and those cities be city ai,1a_{i, 1}, \dots, city ai,dia_{i, d_i}, in ascending order.
  • The ii-th line (1iN)(1 \leq i \leq N) should contain di+1d_i + 1 integers di,ai,1,,ai,did_i, a_{i, 1}, \dots, a_{i, d_i} in this order, separated by spaces.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • 1Ai<BiN(1iM)1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
  • (Ai,Bi)(Aj,Bj)(A_i, B_i) \neq (A_j, B_j) if (ij)(i \neq j).
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

Print NN lines as specified in the Problem Statement.

Sample Input 1

6 6
3 6
1 3
5 6
2 5
1 2
1 6

Sample Output 1

3 2 3 6
2 1 5
2 1 6
0
2 2 6
3 1 3 5

The cities directly connected to city 11 are city 22, city 33, and city 66. Thus, we have d1=3,a1,1=2,a1,2=3,a1,3=6d_1 = 3, a_{1, 1} = 2, a_{1, 2} = 3, a_{1, 3} = 6, so you should print 3,2,3,63, 2, 3, 6 in the first line in this order, separated by spaces.

Note that ai,1,,ai,dia_{i, 1}, \dots, a_{i, d_i} must be in ascending order. For instance, it is unacceptable to print 3,3,2,63, 3, 2, 6 in the first line in this order.

Sample Input 2

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

Sample Output 2

4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

update @ 2024/3/10 11:36:45