#P10289. [GESP样题 八级] 小杨的旅游
[GESP样题 八级] 小杨的旅游
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1108.
Problem Description
Xiao Yang is preparing to travel to Country B.
Country B has cities, numbered from to in order. The cities are connected by bidirectional roads, and any two cities are reachable from each other (that is, there exists a path between any two cities).
Xiao Yang can move between cities via bidirectional roads, and traversing one bidirectional road takes unit of time.
In Country B, there are cities equipped with portals. The indices of the cities with portals are . From any city that has a portal, Xiao Yang can spend units of time to go to another city that has a portal.
Note: If there is a bidirectional road between two portal cities, Xiao Yang may choose either to travel via the road or to teleport via the portals.
Xiao Yang plans to travel in Country B for trips. For the -th trip (), Xiao Yang plans to go from city to city . You are asked to find the minimum time required.
Input Format
The first line contains three positive integers , representing the number of cities in Country B, the number of cities with portals, and the number of trips Xiao Yang plans to make.
The next lines each contain two positive integers , indicating a bidirectional road connecting the two cities.
The -th line contains positive integers, indicating the indices of the cities with portals.
The next lines each contain two positive integers , indicating the starting city index and the destination city index for Xiao Yang’s -th trip.
Output Format
Output lines in total. On the -th line (), output one non-negative integer, representing the minimum time needed for Xiao Yang’s -th trip from city to city .
7 2 1
5 7
3 6
2 3
1 5
5 4
1 2
7 4
3 7
4
5 0 3
2 3
5 1
5 2
1 4
4 5
1 4
4 3
2
1
4
Hint
| Subtask | Score | |||
|---|---|---|---|---|
For all testdata, , , , and .
Translated by ChatGPT 5