#C4380. Reachable Cells in the Dungeon

    ID: 47912 Type: Default 1000ms 256MiB

Reachable Cells in the Dungeon

Reachable Cells in the Dungeon

In this problem, Bruno is imprisoned in a dungeon consisting of N cells connected by M bidirectional passageways. From his current cell S, Bruno can move to any other cell that is reachable through the available passageways. Your task is to determine all the cells that Bruno can reach, excluding his starting cell.

Formally, consider an undirected graph \(G(V,E)\) where \(|V| = N\) and \(|E| = M\). Given a start vertex \(S\), perform a breadth-first search (BFS) to retrieve all the reachable vertices (cells) from \(S\). If no other cell is accessible from \(S\), output NONE.

Note: The output should be a sorted list of reachable cells (in increasing order) as a space separated string, or the string NONE if there are no reachable cells.

inputFormat

The first line contains three integers: N, M, and S where \(1 \le N \le 10^5\), \(0 \le M \le 10^5\) and \(S\) is the starting cell number.

The following M lines each contain two space-separated integers \(u\) and \(v\), representing a bidirectional passage between cell \(u\) and cell \(v\).

outputFormat

If there are any cells reachable from \(S\) (excluding \(S\) itself), output them in increasing order as a single line with cells separated by a space. Otherwise, output the string NONE.

## sample
6 5 1
1 2
2 3
3 4
4 5
5 6
2 3 4 5 6