QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#9533. Classical Counting Problem

统计

给定一棵 $n$ 个节点的无根树,你可以做如下操作若干次:

  • 选择当前树上编号最大或最小的点,删去它和以它为一个端点的所有边,保留任意一个连通块作为操作后的树。

令 $min$ 为树上所有节点编号的最小值,$max$ 为树上所有节点编号的最大值,$size$ 为树上的节点个数,则一棵树的权值为 $min \cdot max \cdot size$。求所有能通过上述操作得到的非空的树的权值和,对 $2^{32}$ 取模。

输入格式

第一行一个正整数 $T(1 \le T \le 10^5)$,表示数据组数。

对于每组数据:

第一行一个正整数 $n(1 \le n \le 10^5)$。

接下来 $n-1$ 行,每行两个正整数 $u,v(1 \le u,v \le n)$,表示树上的一条无向边。保证正确描述了一棵树。

保证对于所有数据,$n$ 的和不超过 $10^5$。

输出格式

对于每组数据,输出一行一个非负整数表示答案对 $2^{32}$ 取模后的结果。

样例输入

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

样例输出

39
35
528
221
1145
1919

子任务

子任务编号 特殊性质 分值
$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$ 给定的树中,每个节点的度数 $\le 2$ $20$
$7$ $25$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.