QOJ.ac

QOJ

Limite de temps : 2.5 s Limite de mémoire : 512 MB Points totaux : 100

#3628. Extreme Expedition

Statistiques

The young computer scientist Kile needs to lose some weight, so he decided to head to Sljeme. While studying hiking maps, Kile noticed that the trails on Sljeme form a tree-like structure. More precisely, he identified them with edges in a tree, while the places where the trails intersect are represented by nodes.

He concluded that the tree consists of $n$ nodes, which he labeled with natural numbers from $1$ to $n$. He then planned $q$ trips, where the $i$-th trip starts at node $a_i$ and ends at node $b_i$. He also somewhat ambitiously estimated that he would cover the distance between any two adjacent nodes in exactly one minute.

However, Kile is not particularly known for his orientation skills. Therefore, after finding himself at any node, he will randomly and uniformly choose the next trail to walk along (among the trails for which that node is one of the endpoints). To help Kile plan his further activities, for each of the $q$ trips, he is interested in the expected time he will spend climbing around Sljeme. That is, he is interested in the expected time (in minutes) to travel from node $a_i$ to node $b_i$ if he moves in the manner described above. Help him!

Note: It is possible to prove that the required expected time can be written in the form of an irreducible fraction $\frac{P}{R}$. To avoid precision issues, it is necessary to output the number $P \cdot R^{-1} \pmod{10^9 + 7}$.

Input

The first line contains the natural numbers $n$ ($2 \le n \le 300\,000$) and $q$ ($1 \le q \le 300\,000$) from the problem description.

The next $n - 1$ lines contain the numbers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$), which indicate that the nodes labeled $u_i$ and $v_i$ are directly connected by an edge. The edges will be such that they form a tree (a simple connected graph without cycles) of $n$ nodes.

In the $i$-th of the next $q$ lines, there are distinct numbers $a_i$ and $b_i$ ($1 \le a_i, b_i \le n$), which represent the starting and ending point of the $i$-th trip.

Output

In the $i$-th line, you need to print the expected duration of the $i$-th trip as described in the problem text.

Examples

Input 1

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

Output 1

11
10
7

Input 2

3 1
1 2
2 3
2 3

Output 2

3

Note

Explanation: There is a 50% probability that the walk will end in one step and a 50% probability that Kile will spend 2 steps to return to node 2 and try again. The expected duration is therefore $\frac{1}{2} \cdot 1 + \frac{1}{2} \cdot (2 + \frac{1}{2} \cdot 1 + \frac{1}{2} \cdot (2 + \frac{1}{2} \cdot 1 + \frac{1}{2} (\dots))) = 3$.

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.