题目描述
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefland is a country with $N$ cities (numbered $1$ through $N$) connected by $M$ bidirectional roads. Chef is on a mission to spread a secret recipe of a Rogan Josh dish. Chef has a sequence $A_{1}, A_{2}, \ldots, A_{K}$ and he must visit cities in the following way: he starts in the city $A_{1}$, travels to the city $A_{2}$, then travels from there to the city $A_{3}$ and so on until he reaches the city $A_{K}$. Note that a city may appear in $A$ multiple times, but $A_{i} \neq A_{i+1}$ for each valid $i$. When travelling between two cities, Chef always follows one of the shortest paths between them (but not necessarily the same one if he travels between them again).
The government is trying to track which cities are targeted by Chef. However, they do not know the sequence $A$. Instead, they have tracked Chef's movement as a sequence $B_{1}, B_{2}, \ldots, B_{L}$ of cities visited by Chef during his mission. Formally, $B_{1} = A_{1}$ is the city where Chef starts, then for each valid $i$, he moves from the city $B_{i}$ to the city $B_{i+1}$ using the direct road between them and finally, he ends his mission in the city $B_{L} = A_{K}$; Chef's sequence $A$ is a subsequence of $B$, since the sequence $B$ also contains all shortest paths which Chef followed. It is guaranteed that there is a direct road between cities $B_{i}$ and $B_{i+1}$ for each valid $i$.
Help the government of Chefland find the minimum possible number of targeted cities, i.e. the minimum possible value of $K$ for a sequence $A$ that corresponds to the given sequence $B$, or determine that no such sequence $A$ exists.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $N$, $M$ and $L$.
The second line contains $L$ space-separated integers $B_{1}, B_{2}, \ldots, B_{L}$.
Each of the following $M$ lines contains three space-separated integers $u$, $v$ and $w$ describing a road between cities $u$ and $v$ with length $w$.
------ Output ------
For each test case, print a single line containing one integer ― the minimum possible $K$, or $-1$ if a valid sequence $A$ does not exist.
------ Constraints ------
$1 ≤ T ≤ 10$
$2 ≤ N ≤ 200$
$1 ≤ M ≤ N \cdot (N-1)/2$
$2 ≤ L ≤ 10,000$
$1 ≤ u, v ≤ N$
$u \neq v$
$1 ≤ w ≤ 10^{6}$
there is at most one direct road between each pair of cities
for each valid $i$, there is a direct road between cities $B_{i}$ and $B_{i+1}$
------ Subtasks ------
Subtask #1 (50 points): $w = 1$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
3
3 3 6
1 2 3 1 2 3
1 2 1
2 3 1
3 1 1
4 4 9
1 2 3 4 1 2 3 4 1
1 2 1
2 3 1
3 4 1
4 1 1
3 3 2
1 2
1 2 3
2 3 1
3 1 1
----- Sample Output 1 ------
6
5
-1
输入格式
见题面
输出格式
见题面