QOJ.ac

QOJ

Limite de temps : 3.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15226. Missing Iris

Statistiques

oql lives in a city consisting of $n$ nodes. In this city, there are $n-1$ bidirectional roads connecting pairs of nodes. It is guaranteed that any two nodes in these $n$ cities can reach each other through these $n-1$ roads, which means these $n$ nodes form a tree structure.

Iris is a cat that likes to wander around. One day, oql finds that Iris is missing! After careful consideration, he decides to go as quickly as possible to a node where Iris's traces might appear.

Among these $n$ nodes, there are $k$ nodes that have shared bicycles. oql starts by walking; walking takes 2 seconds to move to an adjacent node. If a node has a shared bicycle, oql can start riding a bicycle. Riding a bicycle takes only 1 second to move to an adjacent node.

Please tell oql, if oql starts from node $x$ and reaches a node $y$ where Iris's traces might appear, what is the minimum time required? Please note that if node $x$ has a shared bicycle, oql can use it immediately; queries are independent, meaning that after each query, the locations of the shared bicycles do not change. Each node can be visited multiple times.

Input

The first line contains two positive integers $n, k$ ($1 \le k \le n \le 5 \times 10^5$), representing the number of nodes and the number of nodes with shared bicycles.

The next $n-1$ lines each contain two positive integers $x, y$ ($1 \le x, y \le n, x \neq y$), representing a bidirectional road.

The next line contains $k$ distinct integers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le n$), representing the nodes with shared bicycles.

The next line contains an integer $q$ ($1 \le q \le 5 \times 10^5$), representing the number of queries.

The next $q$ lines each contain two integers $x, y$ ($1 \le x, y \le n$), representing a query.

Each integer in each line is separated by a space.

Output

Output $q$ lines, each containing a non-negative integer representing the minimum time.

Examples

Input 1

6 1
1 2
1 3
2 4
2 5
4 6
2
5
1 6
4 6
6 4
1 2
3 6

Output 1

4
2
2
2
6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.