Harry Potter and the Present II

Time Limit: 3000ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 3991
64-bit integer IO format: %I64d      Java class name: Main

Description

Harry and his friends buy a lot of presents now, but they immediately find they had bought too many presents, so they decide to distribute them to the magicians who need them.
To simplify the problem, here we assume the magic world has N cities and M roads, and there are Q requests, at time Ti, someone at city Pi need a present. After planning the route for a while, Harry realizes he can’t do it by himself, he need to find some friends to help him. But the new question is, how many friends Harry should ask at least? We can assume every magician can choose the original city and time to begin his/her journey, and all of them have the same speed, one unit distance per unit time. And if he/she is exactly in city Pi at time Ti, he/she will give the present in a wink, yes, as you see, they are magicians.

Input

The first line contains a single integer T, indicating the number of test cases.
Each test case begins with three integers N, M, Q. Then M lines following, each line contains three integers Ai, Bi, Ci, describing an undirected road. Then Q lines following, each line contains two integers Pi, Ti, describing a request.

Technical Specification

1. 1 <= T <= 50
2. 1 <= N <= 100
3. 1 <= M, Q <= 1 000
4. 0 <= Ai, Bi, Pi < N, Ai != Bi
5. 0 <= Ci, Ti <= 1 000 000 000

Output

For each test case, output the case number first, then the least friend number.

Sample Input

2
2 1 2
0 1 1
0 1
1 2
2 1 2
0 1 2
0 1
1 2

Sample Output

Case 1: 0
Case 2: 1

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .