#abc305e. E - Art Gallery on Graph
E - Art Gallery on Graph
Score : points
问题描述
存在一个简单的无向图,包含 个顶点和 条边。顶点从 到 编号,边则从 到 编号。边 连接顶点 和顶点 。
有 名编号从 到 的警卫驻守在某些顶点上。第 名警卫位于顶点 ,其耐力为 。所有 均不相同。
当满足以下条件时,称顶点 是被保护的:
- 至少存在一名警卫 ,使得顶点 与顶点 之间的距离不大于 。
此处,顶点 和顶点 之间的距离是指连接顶点 和顶点 的路径中最小的边数。
请按升序列出所有被保护的顶点。
以上为通义千问 qwen-max 翻译,仅供参考。
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
update @ 2024/3/10 08:36:50