luogu#P6512. [QkOI#R1] Quark and Flying Pigs

[QkOI#R1] Quark and Flying Pigs

Problem Description

You are given a simple, connected, undirected weighted graph with nn vertices and mm edges. At time 00, you are at vertex 11.

Suppose the current time is tt and you are at vertex vv. You may choose one of the following operations:

  • Stay at vertex vv. After the operation, the time becomes t+1t+1.
  • Choose an edge (a,b,w)(a,b,w) such that a=va=v or b=vb=v. Then you move to the other endpoint of this edge. After the operation, the time becomes t+wt+w.

There are kk pieces of information. Each piece is of the form (ti,vi)(t_i,v_i), meaning that at time tit_i, a flying pig with ID ii will appear at vertex viv_i. If you are at viv_i at that time, then you capture flying pig ii.

Now you need to find the maximum number of flying pigs you can capture.

Input Format

The first line contains three positive integers n,m,kn,m,k.

The next mm lines each contain three positive integers ai,bi,wia_i,b_i,w_i.

The next kk lines each contain two positive integers ti,vit_i,v_i.

Output Format

Output one integer in a single line: the maximum number of flying pigs you can capture.

2 1 5
1 2 2
1 2
2 2
3 2
5 1
7 2

4

Hint

Sample Explanation

The optimal plan is as follows:

At time 00, choose to move to node 22, and the time becomes 22.
At time 22, capture the 22-nd flying pig, choose to stay at node 22, and the time becomes 33.
At time 33, capture the 33-rd flying pig, choose to move to node 11, and the time becomes 55.
At time 55, capture the 44-th flying pig, choose to move to node 22, and the time becomes 77.
At time 77, capture the 55-th flying pig.

Constraints

For 20%20\% of the testdata, n,m,k7n,m,k\le 7.
For 100%100\% of the testdata, 2n2002\le n\le 200, 1mn(n1)21\le m\le \frac{n(n-1)}{2}, 1k50001\le k\le 5000, 1ai,bi,vin1\le a_i,b_i,v_i\le n, 1wi10001\le w_i\le 1000, 1ti1091\le t_i\le 10^9.

Translated by ChatGPT 5