Codeforces Round 1024 (Div. 1)
F
Shoo Shatters the Sunshine
Codeforces
3300
原题
← E→
翻译中…

You are given a tree with $n$ vertices, where each vertex can be colored red, blue, or white. The coolness of a coloring is defined as the maximum distance$^{\text{∗}}$ between a red and a blue vertex.

翻译中…

Formally, if we denote the color of the $i$-th vertex as $c_i$, the coolness of a coloring is $\max d(u, v)$ over all pairs of vertices $1\le u, v\le n$ where $c_u$ is red and $c_v$ is blue. If there are no red or no blue vertices, the coolness is zero.

翻译中…

Your task is to calculate the sum of coolness over all $3^n$ possible colorings of the tree, modulo $998\,244\,353$.

翻译中…

$^{\text{∗}}$The distance between two vertices $a$ and $b$ in a tree is equal to the number of edges on the unique simple path between vertex $a$ and vertex $b$.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2\le n\le 3000$) — the number of vertices in the tree.

翻译中…

Each of the next $n - 1$ lines contains two integers $u$ and $v$ ($1\le u, v\le n$) — the endpoints of the edges of the tree.

翻译中…

It is guaranteed that the given edges form a tree.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output the sum of coolness over all $3^n$ possible colorings of the tree, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, there are $12$ colorings that have at least one blue and one red node. The following pictures show their coloring and their coolness:

翻译中…

image All these colorings have coolness $2$

翻译中…

image All these colorings have coolness $1$

翻译中…

Therefore, the sum of coolness over all possible colorings is $6\cdot 2 + 6\cdot 1 = 18$.

翻译中…

In the second test case, the following are some examples of colorings with a coolness of $3$:

翻译中…

image

翻译中…

样例

Input #1
3
3
1 2
2 3
6
1 2
1 3
1 4
3 5
5 6
17
1 2
1 3
1 4
1 5
2 6
2 7
2 8
3 9
3 10
7 11
7 12
11 13
13 14
14 15
10 16
16 17
Output #1
18
1920
78555509
InputCopy OutputCopy
题目信息
题号
2101F
时间限制
7 s
内存限制
256 MB
标签
组合数学
动态规划
树

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