Under construction

Still being built. Things may change

Reimu's Teleportation Practice

Time limit6sMemory limit1024 MB

Summary
Given a tree where K nodes are priests who can teleport to any priest with equal chance, find the minimum expected moves from A to B.
Level

Hard8 of 10

Topics
Tree, Dynamic programming, Probability
Solved
No attempts yet

Problem

In Reimu's world of Gensokyo, there are NN gentlemen. Among them, KK are Myojin priests who serve the deity Myojin. Two gentlemen are connected by N−1N-1 bidirectional roads, and any two gentlemen can reach each other using one or more roads. Over QQ days, Reimu decides to practice her ability, teleportation. On day ii, she starts at gentleman AiA_i and wants to reach gentleman BiB_i, where Marisa is. Reimu moves between gentlemen using the following actions.

  • Pick one of the gentlemen directly connected to the current one by a road and move there.
  • If the current gentleman is a Myojin priest, teleport to one of the KK Myojin priests, including the current one, chosen with equal probability.

Marisa wants Reimu to finish her practice quickly so they can play, so she wants to tell Reimu which actions to use in what order. At every step, Reimu chooses the action that minimizes the expected number of actions needed to reach BiB_i. Print the expected number of actions to go from AiA_i to BiB_i.

Input

The first line contains NN, KK, and QQ separated by spaces. (2≤N≤1000002 \le N \le 100000; 1≤K≤N1 \le K \le N; 1≤Q≤5000001 \le Q \le 500000) Each of the next N−1N-1 lines contains uiu_i and viv_i, meaning gentleman uiu_i and gentleman viv_i are connected by a road. (1≤ui<vi≤N1 \le u_i < v_i \le N) It is guaranteed that any two gentlemen can reach each other using one or more roads. The next line contains the numbers of the Myojin priests p1,p2,⋯ ,pKp_1, p_2, \cdots, p_K. (1≤p1<p2<⋯<pK≤N1 \le p_1 < p_2 < \cdots < p_K \le N) Each of the next QQ lines contains AiA_i and BiB_i, meaning on day ii Reimu goes from gentleman AiA_i to gentleman BiB_i. (1≤Ai,Bi≤N1 \le A_i, B_i \le N; Ai≠BiA_i \ne B_i)

Output

Print QQ lines. On line ii, print the expected number of actions to go from AiA_i to BiB_i. Your answer must have a relative error of at most 10−910^{-9} against the correct answer.

Examples1

  1. Example 1

    Input
    8 5 2
    1 2
    2 3
    3 4
    4 5
    4 6
    4 7
    4 8
    1 5 6 7 8
    1 4
    4 1
    
    Expected output
    2.25
    3