CF1458F.Range Diameter Sum
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with n vertices numbered 1,…,n . A tree is a connected simple graph without cycles.
Let dist(u,v) be the number of edges in the unique simple path connecting vertices u and v .
Let diam(l,r)=maxdist(u,v) over all pairs u,v such that l≤u,v≤r .
Compute ∑1≤l≤r≤ndiam(l,r) .
输入格式
The first line contains a single integer n ( 1≤n≤105 ) — the number of vertices in the tree.
The next n−1 lines describe the tree edges. Each of these lines contains two integers u,v ( 1≤u,v≤n ) — endpoint indices of the respective tree edge. It is guaranteed that the edge list indeed describes a tree.
输出格式
Print a single integer — ∑1≤l≤r≤ndiam(l,r) .
输入输出样例
输入#1
4 1 2 2 4 3 2
输出#1
10
输入#2
10 1 8 2 9 5 6 4 8 4 2 7 9 3 6 10 4 3 9
输出#2
224