cswork / OAOpen practice workspace

Akuna CapitalOA #13

Delivery Management System (QR Intern)

Estimated MediumJudge-ready

Topics (AI-labelled)Shortest Paths

Cities and two-way roads form an unweighted graph. Starting from the city where the factory is located, deliver in ascending order of shortest-path distance; ties in distance are broken by ascending city number. Unreachable cities are not output, and neither is the start city itself.

Input

The first line contains n, m and company (cities are numbered 1..n); each of the next m lines contains a two-way road u v. Site-added ranges: 1≤n≤100000, 0≤m≤200000; the graph has no self-loops and no duplicate edges.

Output

Output the visited city numbers on one line, separated by spaces. If no other city is reachable, output an empty line.

Example 1

Input:

4 3 1
1 2
2 3
2 4

Output:

2 3 4

Example 2

Input:

5 4 1
1 4
4 5
1 2
2 3

Output:

2 4 3 5

Example 3

Input:

3 0 1

Output:

Editorial

Loading solution…