F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Visit relatives

Time 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
1 7 11 5 0 1 0 2 1 2 1 4 0 3 3 4 4 6 2 6 6 5 3 5 4 5 1 2 1 3 2 0 1 4 5 3
 

Sample Output
7
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 10:14:20, Gzip enabled