SDE Path

Breadth-First Search Traversal

Easy

Breadth-First Search Traversal

Perform a BFS traversal of a graph starting from a given node.

Input format

The first line contains N, M, and SRC. The next M lines contain edge pairs (undirected).

Output format

Print BFS traversal starting from SRC (only the component containing SRC), ascending neighbors.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
9 5 0
2 4
3 5
2 8
1 5
0 5
Expected output
0 5 1 3
Example 2
Input
5 3 0
0 4
1 4
1 2
Expected output
0 4 1 2