Type: Default 1000ms 256MiB

dfs遍历

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

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

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 4 3 5

Note

对于所有的数据,1<=n,m<=101<=n,m<=10