P r o b l e m \mathrm{Problem} Problem
Famil Door’s City map looks like a tree (undirected connected acyclic graph) so other people call it Treeland. There are n n n intersections in the city connected by n ? 1 n-1 n?1 bidirectional roads.
There are m m m friends of Famil Door living in the city. The i i i -th friend lives at the intersection u i u_{i} ui? and works at the intersection v i v_{i} vi? . Everyone in the city is unhappy because there is exactly one simple path between their home and work.
Famil Door plans to construct exactly one new road and he will randomly choose one among n ? ( n ? 1 ) / 2 n·(n-1)/2 n?(n?1)/2 possibilities. Note, that he may even build a new road between two cities that are already connected by one.
He knows, that each of his friends will become happy, if after Famil Door constructs a new road there is a path from this friend home to work and back that doesn't visit the same road twice. Formally, there is a simple cycle containing both u i u_{i} ui? and v i v_{i} vi? .
Moreover, if the friend becomes happy, his pleasure is equal to the length of such path (it's easy to see that it's unique). For each of his friends Famil Door wants to know his expected pleasure, that is the expected length of the cycle containing both u i u_{i} ui? and$ v_{i}$ if we consider only cases when such a cycle exists.
T r a n s l a t i o n \mathrm{Translation} Translation
给出一棵 n n n 个节点的树。
有 m m m 个询问,每一个询问包含两个数 a 、 b a、b a、b,
我们可以对任意两个不相连的点连一条无向边,
并且使得加上这条边后 a , b a,b a,b 处在一个环内。
对于每一个询问,求这样的环的期望长度。
S o l u t i o n \mathrm{Solution} Solution
这道题我们需要分类讨论。
当询问节点 u u u 和 v v v 无祖先关系时。
我们在两个节点的子树中个选择一个点即能构成环。
那个方案数为 s i z e u × s i z e v \mathrm{size_u}\times \mathrm{size_v} sizeu