eolymp
bolt
Try our new interface for solving problems
Problems

Merry Christmas

Merry Christmas

International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at specified time of December 24. Although same Santa can deliver two or more presents, because it takes time to move between houses, two or more Santa might be needed to finish all the requests on time. Employing Santa needs much money, so the president of ICPC employed you, a great programmer, to optimize delivery schedule. Your task is to write a program to calculate the minimum number of Santa necessary to finish the given requests on time. Because each Santa has been well trained and can conceal himself in the town, you can put the initial position of each Santa anywhere. \InputFile The input consists of several datasets. Each dataset is formatted as follows. \textbf{N M L u_1 v_1 d_1 u_2 v_2 d_2 ... u_M v_M d_M p_1 t_1 p_2 t_2 ... p_L t_L} The first line of a dataset contains three integer, \textbf{N}, \textbf{M} and \textbf{L} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}, \textbf{0} ≤ \textbf{M} ≤ \textbf{1000}, \textbf{1} ≤ \textbf{L} ≤ \textbf{1000}) each indicates the number of houses, roads and requests respectively. The following \textbf{M} lines describe the road network. The \textbf{i}-th line contains three integers, \textbf{u_i}, \textbf{v_i}, and \textbf{d_i} (\textbf{0} ≤ \textbf{u_i} < \textbf{v_i} ≤ \textbf{N−1}, \textbf{1} ≤ \textbf{d_i} ≤ \textbf{100}) which means that there is a road connecting houses \textbf{u_i} and \textbf{v_i} with \textbf{d_i} length. Each road is bidirectional. There is at most one road between same pair of houses. Whole network might be disconnected. The next \textbf{L} lines describe the requests. The \textbf{i}-th line contains two integers, \textbf{p_i} and \textbf{t_i} (\textbf{0} ≤ \textbf{p_i} ≤ \textbf{N−1}, \textbf{0} ≤ \textbf{t_i} ≤ \textbf{10^8}) which means that there is a delivery request to house \textbf{p_i} on time \textbf{t_i}. There is at most one request for same place and time. You can assume that time taken other than movement can be neglectable, and every Santa has the same speed, one unit distance per unit time. The end of the input is indicated by a line containing three zeros separated by a space, and you should not process this as a test case. \OutputFile Print the minimum number of Santa necessary to finish all the requests on time.
Time limit 30 seconds
Memory limit 256 MiB
Input example #1
3 2 3
0 1 10
1 2 10
0 0
1 10
2 0
3 2 4
0 1 10
1 2 10
0 0
1 10
2 20
0 40
10 10 10
0 1 39
2 3 48
3 5 20
4 8 43
3 9 10
8 9 40
3 4 5
5 7 20
1 7 93
1 3 20
0 0
1 100000000
2 100
3 543
4 500
5 400
6 300
7 200
8 100
9 100
0 0 0
Output example #1
2
1
4
Source ACM International Collegiate Programming Contest JAG Practice Contest, Tokyo, 2010-11-28