|
||||||||||
Visit relativesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 248 Accepted Submission(s): 13 Problem Description When Wiskey return home, many relatives he need to visit, and he will buy some gifts before he visit his relatives. There is a map which has N places; Wiskey's house is labeled 0. He has T tasks which from u to v, it mean Wiskey could go to v when he bought a gift at u before. Wiskey always start at 0, and must end with 0. Tell him how many minimum total places he went when he finished all tasks. Input First line will contain one integer mean how many cases will follow by; the number of cases wills less than 20. In each case will contain three integers N means the number of places, M roads and T tasks. (1 <= N <= 20, 0 <= M <= 100, 0 <= T <= 5). First, M roads will be follow; the road is bi-connected. Second, T tasks will be follow; you are remember the u must went earlier than v, then what makes the task will be finished. Output Print the minimum total number of places he went. If Wiskey can't finish all tasks, please print -1. Sample Input
Sample Output
Hint One way is 0-1-2-0-1-4-5-3-0, the length is 8, and it finished all tasks. The way is 0-1-2-1-4-5-3-0 which is minimum length. Author Wiskey | ||||||||||
|