CF1106D.Lunar New Year and a Wander
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.
The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the node 1 and he records 1 on his notebook. He can wander from one node to another through those bidirectional edges. Whenever he visits a node not recorded on his notebook, he records it. After he visits all nodes at least once, he stops wandering, thus finally a permutation of nodes a1,a2,…,an is recorded.
Wandering is a boring thing, but solving problems is fascinating. Bob wants to know the lexicographically smallest sequence of nodes he can record while wandering. Bob thinks this problem is trivial, and he wants you to solve it.
A sequence x is lexicographically smaller than a sequence y if and only if one of the following holds:
- x is a prefix of y , but x=y (this is impossible in this problem as all considered sequences have the same length);
- in the first position where x and y differ, the sequence x has a smaller element than the corresponding element in y .
输入格式
The first line contains two positive integers n and m ( 1≤n,m≤105 ), denoting the number of nodes and edges, respectively.
The following m lines describe the bidirectional edges in the graph. The i -th of these lines contains two integers ui and vi ( 1≤ui,vi≤n ), representing the nodes the i -th edge connects.
Note that the graph can have multiple edges connecting the same two nodes and self-loops. It is guaranteed that the graph is connected.
输出格式
Output a line containing the lexicographically smallest sequence a1,a2,…,an Bob can record.
输入输出样例
输入#1
3 2 1 2 1 3
输出#1
1 2 3
输入#2
5 5 1 4 3 4 5 4 3 2 1 5
输出#2
1 4 3 2 5
输入#3
10 10 1 4 6 8 2 5 3 7 9 4 5 6 3 4 8 10 8 9 1 10
输出#3
1 4 3 7 9 8 6 5 2 10
说明/提示
In the first sample, Bob's optimal wandering path could be 1→2→1→3 . Therefore, Bob will obtain the sequence {1,2,3} , which is the lexicographically smallest one.
In the second sample, Bob's optimal wandering path could be 1→4→3→2→3→4→1→5 . Therefore, Bob will obtain the sequence {1,4,3,2,5} , which is the lexicographically smallest one.