Type: Default 1000ms 256MiB

树上计数

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

树上计数

题目描述

给定一棵树,标号从 11nn,求无序三元组 (x,y,z)(x,y,z) 的数量满足 dist(x,y)=dist(y,z)=dist(x,z)dist(x,y)=dist(y,z)=dist(x,z)x,y,zx,y,z 互不相等。

其中 dist(x,y)dist(x,y) 表示 xxyy 在树上的距离。

输入格式

第一行一个正整数 nn,表示点数。

接下去 n1n-1 行,每行两个正整数 x,yx,y,描述了树上的一条边,连接 x,yx,y

输出格式

上述三元组数量。

样例

Input 1

7
1 2
5 7
2 5
2 3
5 6
4 5

Output 1

5

不同的三元组有:

{1,3,5},{2,4,6},{2,4,7},{2,6,7},{4,6,7}

提示说明

对于前 0%0\% 的数据,是样例。

对于前 20%20\% 的数据,保证 n100n\le 100

对于前 30%30\% 的数据,保证 n5000n\le 5000

对于另外 30%30\% 的数据,保证 n105n\le 10^5,且数据随机。

对于 100%100\% 的数据,保证 n105n\le 10^5

暴力、部分分训练

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2024-10-6 14:00
End at
2024-10-6 18:00
Duration
4 hour(s)
Host
Partic.
4