#abc305e. [abc305_e]Art Gallery on Graph

[abc305_e]Art Gallery on Graph

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

  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • $0 \\leq M \\leq \\min \\left(\\frac{N(N-1)}{2}, 2 \\times 10^5 \\right)$
  • 1leqKleqN1 \\leq K \\leq N
  • 1leqai,bileqN1 \\leq a_i, b_i \\leq N
  • The given graph is simple.
  • 1leqpileqN1 \\leq p_i \\leq N
  • All pip_i are distinct.
  • 1leqhileqN1 \\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\\vdots aMa_M bMb_M p1p_1 h1h_1 p2p_2 h2h_2 vdots\\vdots pKp_K hKh_K

Output

Print the answer in the following format. Here,

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

GG v1v_1 v2v_2 dots\\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