QOJ.ac

QOJ

时间限制: 3 s 内存限制: 1024 MB 总分: 100

#9533. Classical Counting Problem

统计

Given an unrooted tree with $n$ nodes, you can perform the following operation any number of times:

  • Choose the node with the smallest or largest index currently in the tree, remove it and all edges incident to it, and keep any one of the resulting connected components as the tree for the next step.

Let $min$ be the minimum index of all nodes in the tree, $max$ be the maximum index of all nodes in the tree, and $size$ be the number of nodes in the tree. The weight of a tree is defined as $min \cdot max \cdot size$. Calculate the sum of the weights of all possible non-empty trees that can be obtained through the above operations, modulo $2^{32}$.

Input

The first line contains a positive integer $T(1 \le T \le 10^5)$, representing the number of test cases.

For each test case:

The first line contains a positive integer $n(1 \le n \le 10^5)$.

The next $n-1$ lines each contain two positive integers $u, v(1 \le u, v \le n)$, representing an undirected edge in the tree. It is guaranteed that the input describes a valid tree.

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

Output

For each test case, output a single non-negative integer representing the answer modulo $2^{32}$.

Examples

Input 1

6
3
1 2
2 3
3
1 3
2 3
7
2 1
3 1
4 1
5 1
6 5
7 6
6
2 1
3 1
4 1
5 4
6 1
9
2 1
3 2
4 3
5 1
6 4
7 5
8 2
9 3
9
2 1
3 2
4 3
5 4
6 5
7 2
8 3
9 5

Output 1

39
35
528
221
1145
1919

Subtasks

Subtask ID Special Property Score
$1$ $n \le 10$ $5$
$2$ $n \le 20$ $10$
$3$ $n \le 100$ $10$
$4$ $n \le 2000$ $15$
$5$ $n \le 3 \times 10^4$ $15$
$6$ The degree of each node in the given tree is $\le 2$ $20$
$7$ None $25$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.