#abc305e. E - Art Gallery on Graph

E - Art Gallery on Graph

Score : 475475 points

问题描述

存在一个简单的无向图,包含 NN 个顶点和 MM 条边。顶点从 11NN 编号,边则从 11MM 编号。边 ii 连接顶点 aia_i 和顶点 bib_i

KK 名编号从 11KK 的警卫驻守在某些顶点上。第 ii 名警卫位于顶点 pip_i,其耐力为 hih_i。所有 pip_i 均不相同。

当满足以下条件时,称顶点 vv被保护的

  • 至少存在一名警卫 ii,使得顶点 vv 与顶点 pip_i 之间的距离不大于 hih_i

此处,顶点 uu 和顶点 vv 之间的距离是指连接顶点 uu 和顶点 vv 的路径中最小的边数。

请按升序列出所有被保护的顶点。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a simple undirected graph with NN vertices and MM edges, where vertices are numbered from 11 to NN, and edges are numbered from 11 to MM. Edge ii connects vertex aia_i and vertex bib_i.
KK security guards numbered from 11 to KK are on some vertices. Guard ii is on vertex pip_i and has a stamina of hih_i. All pip_i are distinct.

A vertex vv is said to be guarded when the following condition is satisfied:

  • there is at least one guard ii such that the distance between vertex vv and vertex pip_i is at most hih_i.

Here, the distance between vertex uu and vertex vv is the minimum number of edges in the path connecting vertices uu and vv.

List all guarded vertices in ascending order.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • $0 \leq M \leq \min \left(\frac{N(N-1)}{2}, 2 \times 10^5 \right)$
  • 1KN1 \leq K \leq N
  • 1ai,biN1 \leq a_i, b_i \leq N
  • The given graph is simple.
  • 1piN1 \leq p_i \leq N
  • All pip_i are distinct.
  • 1hiN1 \leq h_i \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM KK

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aMa_M bMb_M

p1p_1 h1h_1

p2p_2 h2h_2

\vdots

pKp_K hKh_K

Output

Print the answer in the following format. Here,

  • GG is the number of guarded vertices,

  • and v1,v2,,vGv_1, v_2, \dots, v_G are the vertex numbers of the guarded vertices in ascending order.

GG

v1v_1 v2v_2 \dots vGv_G

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 1,2,3,51, 2, 3, 5.
These vertices are guarded because of the following reasons.

  • The distance between vertex 11 and vertex p1=1p_1 = 1 is 00, which is not greater than h1=1h_1 = 1. Thus, vertex 11 is guarded.
  • The distance between vertex 22 and vertex p1=1p_1 = 1 is 11, which is not greater than h1=1h_1 = 1. Thus, vertex 22 is guarded.
  • The distance between vertex 33 and vertex p2=5p_2 = 5 is 11, which is not greater than h2=2h_2 = 2. Thus, vertex 33 is guarded.
  • The distance between vertex 55 and vertex p1=1p_1 = 1 is 11, which is not greater than h1=1h_1 = 1. Thus, vertex 55 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