2014
01-04

# Visit relatives

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.

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).
Second, T tasks will be follow; you are remember the u must went earlier than v, then what makes the task will be finished.

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).
Second, T tasks will be follow; you are remember the u must went earlier than v, then what makes the task will be finished.

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

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.


1. 如果两个序列的最后字符不匹配（即X [M-1]！= Y [N-1]）
L（X [0 .. M-1]，Y [0 .. N-1]）= MAX（L（X [0 .. M-2]，Y [0 .. N-1]），L（X [0 .. M-1]，Y [0 .. N-1]）
这里写错了吧。