Problem list
Log in
#r03339 · Online Judge > GoldOJ

Reachable Vertices

Silver III 2.0 s 256 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code