#P2096. Random Walk On Tree

Random Walk On Tree

题目描述

点击查看pdf

MianKing has a tree with nn nodes. And he has one black chess and one white chess, both of the chess are initially on some nodes of the tree.

Now MianKing will do the following operation until the black chess and the white chess are on the same node: If the black chess is on node xx, let SS denote the set of nodes which connect to xx directly. Then MainKing will choose a node of SS randomly and move the black chess to it.

Let LenLen denote the number of operations MianKing did, now let f(S,T)f(S,T) denote the expectation of Len2Len^2 when the black chess is on node SS and the white chess is on node TT initially.

Let Sub(x)Sub(x) denote the set of all of the nodes in the subtree of xx when the root is node 11. Now MainKing wants you to answer QQ questions, each question formed by two integers AA,BB and you need to answer

It's guaranteed that Sub(x)capSub(y)=emptysetSub(x)\\cap Sub(y)=\\emptyset for each questions.

If the answer is irreducible fraction fracxy\\frac{x}{y}, you need to output an integer dd in [0,998244352][0,998244352] which satisfies dy mod 998244353=xd*y~mod~998244353=x. It's guaranteed that y mod 998244353 eq0y~mod~998244353\ eq 0

输入格式

The first line has two integers n,Qn,Q.

Then there are n1n-1 lines, each line has two integers (x,y)(x,y) denotes an edge of the tree.

Then there are QQ lines, the i-th line has two integers (A,B)(A,B) denotes the i-th questions.

1leqn,Qleq1051\\leq n,Q\\leq 10^5

It's guaranteed that Sub(A)capSub(B)=emptysetSub(A)\\cap Sub(B)=\\emptyset for each questions.

输出格式

There are QQ lines, thee i-th line has one integer denotes the answer. If the answer is irreducible fraction fracxy\\frac{x}{y}, you need to output an integer dd in [0,998244352][0,998244352] which satisfies dy mod 998244353=xd*y~mod~998244353=x. It's guaranteed that y mod 998244353 eq0y~mod~998244353\ eq 0

样例

3 1 
1 2 
1 3 
2 3 

24 

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

6508 
408 
2833 
960 

提示

Form 2020ICPC济南站