#abc305e. [abc305_e]Art Gallery on Graph
[abc305_e]Art Gallery on Graph
Problem Statement
There is a simple undirected graph with vertices and edges, where vertices are numbered from to , and edges are numbered from to . Edge connects vertex and vertex .
security guards numbered from to are on some vertices. Guard is on vertex and has a stamina of . All are distinct.
A vertex is said to be guarded when the following condition is satisfied:
- there is at least one guard such that the distance between vertex and vertex is at most .
Here, the distance between vertex and vertex is the minimum number of edges in the path connecting vertices and .
List all guarded vertices in ascending order.
Constraints
- $0 \\leq M \\leq \\min \\left(\\frac{N(N-1)}{2}, 2 \\times 10^5 \\right)$
- The given graph is simple.
- All are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in the following format. Here,
- is the number of guarded vertices,
- and are the vertex numbers of the guarded vertices in ascending order.
Sample Input 1
5 5 2
1 2
2 3
2 4
3 5
1 5
1 1
5 2
Sample Output 1
4
1 2 3 5
The guarded vertices are .
These vertices are guarded because of the following reasons.
- The distance between vertex and vertex is , which is not greater than . Thus, vertex is guarded.
- The distance between vertex and vertex is , which is not greater than . Thus, vertex is guarded.
- The distance between vertex and vertex is , which is not greater than . Thus, vertex is guarded.
- The distance between vertex and vertex is , which is not greater than . Thus, vertex is guarded.
Sample Input 2
3 0 1
2 3
Sample Output 2
1
2
The given graph may have no edges.
Sample Input 3
10 10 2
2 1
5 1
6 1
2 4
2 5
2 10
8 5
8 6
9 6
7 9
3 4
8 2
Sample Output 3
7
1 2 3 5 6 8 9