当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7202:Maex

题目描述
You are given a rooted tree consisting of $n$ vertices numbered from $1$ to $n$, and the root is vertex $1$.

Vertex $i$ has a natural number weight $a_i$, and $\textbf{no two different vertexes have the same weight}$.

Define $b_u = MEX$ { $x \space | \space \exists v \in subtree\left( u \right), x = a_v\$}.

Unfortunately, $a_i$ are not given. Please find out the maximum possible $\sum_{i=1}^{n}b_i$.

The $\textbf{MEX}$ of a set is the minimum non-negative integer that doesn't belong to the set.
输入解释
The first line contains one integer $T \left( 1 \leq T \leq 10 \right)$, indicating the number of test cases.

For each test case:

The first line contains one integer $n \left( 1 \le n \le 5 \cdot 10^5 \right)$, indicating the number of nodes.

In the following $n-1$ lines, each line contains two interger $u, v \left(1 \le u, v \le n \right)$, indicating an edge $\left( u, v \right)$ of the tree.

A guarantee is that forming trees.
输出解释
For each test case:
One line with an integer, indicating the maximum possible $\sum_{i=1}^{n}b_i$.
输入样例
3
5
1 2
3 2
1 5
4 1
3
1 2
2 3
1
输出样例
8
6
1

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7202

最后修改于 2022-09-15T06:17:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 262144/131072K(Java/Others)