cswork / OA打开练习工作台

Akuna CapitalOA #13

Delivery Management System (QR Intern)

估计中等可在线判题

考点(AI 标注)最短路

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.

输入格式

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 the visited city numbers on one line, separated by spaces. If no other city is reachable, output an empty line.

样例 1

输入:

4 3 1
1 2
2 3
2 4

输出:

2 3 4

样例 2

输入:

5 4 1
1 4
4 5
1 2
2 3

输出:

2 4 3 5

样例 3

输入:

3 0 1

输出: