#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 nn cities, numbered from 11 to nn in order. The cities are connected by n1n-1 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 11 unit of time.

In Country B, there are kk cities equipped with portals. The indices of the cities with portals are b1,b2,,bkb_1,b_2, \cdots ,b_k. From any city that has a portal, Xiao Yang can spend 00 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 qq trips. For the ii-th trip (1iq1 \le i \le q), Xiao Yang plans to go from city uiu_i to city viv_i. You are asked to find the minimum time required.

Input Format

The first line contains three positive integers n,k,qn,k,q, 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 n1n-1 lines each contain two positive integers xi,yix_i, y_i, indicating a bidirectional road connecting the two cities.
The (n+1)(n + 1)-th line contains kk positive integers, indicating the indices of the cities with portals.
The next qq lines each contain two positive integers ui,viu_i,v_i, indicating the starting city index and the destination city index for Xiao Yang’s ii-th trip.

Output Format

Output qq lines in total. On the ii-th line (1iq1 \leq i \leq q), output one non-negative integer, representing the minimum time needed for Xiao Yang’s ii-th trip from city uiu_i to city viv_i.

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 nn \leq k k \leq qq \leq
11 3030 500500 11
22 2×1052 \times 10^5 00 2×1052 \times 10^5
33 4040 2×1052 \times 10^5

For all testdata, 1n2×1051 \leq n \leq 2 \times 10^5, 0kn0 \leq k \leq n, 1xi,yi,ui,vin1 \leq x_i, y_i, u_i, v_i \leq n, and uiviu_i \neq v_i.

Translated by ChatGPT 5