F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Maex

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 1080    Accepted Submission(s): 448


Problem Description
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.
 

Input
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.
 

Output
For each test case:
One line with an integer, indicating the maximum possible $\sum_{i=1}^{n}b_i$.
 

Sample Input
3 5 1 2 3 2 1 5 4 1 3 1 2 2 3 1
 

Sample Output
8 6 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-06 17:23:22, Gzip enabled