atcoder#ABC305E. [ABC305E] Art Gallery on Graph
[ABC305E] Art Gallery on Graph
Score : points
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.
5 5 2
1 2
2 3
2 4
3 5
1 5
1 1
5 2
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.
3 0 1
2 3
1
2
The given graph may have no edges.
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
7
1 2 3 5 6 8 9