CF1830D.Mex Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree with nn nodes. For each node, you either color it in 00 or 11 .

The value of a path (u,v)(u,v) is equal to the MEX ^\dagger of the colors of the nodes from the shortest path between uu and vv .

The value of a coloring is equal to the sum of values of all paths (u,v)(u,v) such that 1uvn1 \leq u \leq v \leq n .

What is the maximum possible value of any coloring of the tree?

^{\dagger} The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:

  • The MEX of [2,2,1][2,2,1] is 00 , because 00 does not belong to the array.
  • The MEX of [3,1,0,1][3,1,0,1] is 22 , because 00 and 11 belong to the array, but 22 does not.
  • The MEX of [0,3,1,2][0,3,1,2] is 44 because 00 , 11 , 22 , and 33 belong to the array, but 44 does not.

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of nodes in the tree.

The following n1n-1 lines of each test case contains 22 integers aia_i and bib_i ( 1ai,bin,aibi1 \leq a_i, b_i \leq n, a_i \neq b_i ) — indicating an edge between vertices aia_i and bib_i . It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print the maximum possible value of any coloring of the tree.

输入输出样例

  • 输入#1

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

    输出#1

    8
    15
    96
    1

说明/提示

In the first sample, we will color vertex 22 in 11 and vertices 1,31,3 in 00 . After this, we consider all paths:

  • (1,1)(1,1) with value 11
  • (1,2)(1,2) with value 22
  • (1,3)(1,3) with value 22
  • (2,2)(2,2) with value 00
  • (2,3)(2,3) with value 22
  • (3,3)(3,3) with value 11

We notice the sum of values is 88 which is the maximum possible.

首页