Type: Default 1000ms 256MiB

bfs遍历

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

马上到寒假了,JXY准备去n大城市游玩。这些城市之间有些有航线,有些没有。由于JXY特别懒,现在他想请一个更蒟蒻的人AYX帮他查一下航线的数量,JXY在1号城市,由近到远输出所有他能游玩的城市编号。(小天才WQG提醒:请使用广度优先遍历)

Input Format

第一行:m和n,m代表城市数,n代表道路数量。

下面n行,每行两个数a、b,代表城市a、b之间有一条路。

Output Format

输出图的广度优先遍历

注意:航线是双向的,并且搜索时,请根据子节点编号最小优先的规则遍历

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

Note

1<=n,m<=101<=n,m<=10