#P5304. [GXOI/GZOI2019] 旅行者
[GXOI/GZOI2019] 旅行者
Description
Country J has cities, connected by one-way roads. The length of each road is known.
One day, Rainbow, who lives in Country J, invites Vani to visit. However, as an experienced traveler, Vani is only interested in cities in Country J that have a long history and unique natural scenery.
To improve the travel experience, Vani wants to know the minimum value among the “pairwise shortest paths” between the cities he is interested in (that is, among all pairs of cities he is interested in, the shortest-path distance of the closest pair).
You may have already guessed the story — Vani will be busy traveling elsewhere these days, so please help him solve this problem.
Input Format
Each test point contains multiple test cases. The first line is an integer , the number of test cases. Note that the test cases are independent of each other.
For each test case, the first line contains three positive integers , representing cities in Country J (numbered from ), roads, and the number of cities that Vani is interested in.
The next lines each contain positive integers , indicating that there is a one-way road from city to city with length . Note that and may be equal, and the same pair may appear multiple times.
The next line contains positive integers, the indices of the cities that Vani is interested in.
Output Format
The output should contain lines. For each test case, output one integer: the minimum value among the pairwise shortest-path distances between the cities.
2
6 7 3
1 5 3
2 3 5
1 4 3
5 3 2
4 6 5
4 3 7
5 6 4
1 3 6
7 7 4
5 3 10
6 2 7
1 2 6
5 4 2
4 3 4
1 7 3
7 2 4
1 2 5 3
5
6
Hint
Sample Explanation
For the first test case, the shortest path from to is ; from to is ; and cannot reach each other. So the closest pair is , and the minimum distance is .
For the second test case, the shortest path from to is ; from to is ; all other pairs of points cannot reach each other. So the closest pairs are and , and the minimum distance is .
Constraints
, , , .
| Test Point ID | Scale of | Scale of | Notes |
|---|---|---|---|
| None | |||
| The graph is guaranteed to be a directed acyclic graph | |||
| None | |||
Admin note on 2024-12-18: There may be self-loops in test point 5。
Translated by ChatGPT 5
京公网安备 11011102002149号