Given an undirected graph and a start vertex $V$, print in ascending order all vertices reachable from $V$ (including $V$ itself).
Input
First line $N$, $M$, $V$; then $M$ lines each with an edge $u$, $v$ ($1 \le N, M \le 1000$, $u \ne v$). Multiple edges may appear.
Output
Print the reachable vertices in ascending order, space-separated.
Example 1
Input
4 5 1 1 2 1 3 2 3 2 4 3 4
Output
1 2 3 4
Example 2
Input
6 4 5 1 2 2 3 3 1 4 6
Output
5
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.