Pinely Round 5 (Div. 1 + Div. 2)
F
SubMST
Codeforces
3000
原题
← EG →
翻译中…

You are given an undirected unweighted tree $T$ with $n$ vertices.

翻译中…

Define a complete undirected weighted graph $G$ with $n$ vertices, where the weight of the edge between vertices $u$ and $v$ in $G$ is equal to the distance between the two vertices in the original tree.

翻译中…

For every possible subset of vertices, consider the minimum spanning tree (MST) of the subgraph of $G$ induced by that subset of vertices. Compute the sum of the weights of the MST for all possible subsets of vertices.

翻译中…

As this number is big, you are only required to output the sum modulo $10^9 + 7$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10000$). The description of the test cases follows.

翻译中…

The first line contains an integer $n$ ($1 \leq n \leq 5000$), the number of vertices in the tree.

翻译中…

The following $n-1$ lines contains two integers $u$ and $v$ ($1 \leq u,v \leq n$), representing an edge between vertices $u$ and $v$ in the tree.

翻译中…

It is guaranteed that the sum of $n^2$ over all test cases does not exceed $5000^2$.

翻译中…

Output

翻译中…

Output a single integer, the sum of the MST weights for all possible subsets of vertices, modulo $10^9+7$.

翻译中…

Note

翻译中…

The first test case is illustrated below. The subsets with at most one vertex are ommited since they have a weight of $0$ and therefore do not contribute to the sum.

翻译中…

image

翻译中…

样例

Input #1
5
3
1 2
2 3
7
3 1
1 2
3 5
4 5
3 6
6 7
22
4 11
9 7
3 18
19 8
16 20
5 22
13 20
15 12
2 8
12 1
17 4
6 7
1 21
10 18
7 3
20 15
14 21
18 4
8 15
22 17
11 14
1
2
2 1
Output #1
6
496
74069416
0
1
InputCopy OutputCopy
题目信息
题号
2161F
时间限制
5 s
内存限制
256 MB
标签
组合数学
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。