CF1458F.Range Diameter Sum
NOI/NOI+/CTSC
通过率:0%
时间限制:7.00s
内存限制:512MB
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).
给你一棵包含 n 个顶点的树,顶点编号为 1,…,n。树是一种无环的连通简单图。
令 dist(u,v) 表示连接顶点 u 和 v 的唯一简单路径所含的边数。
令 diam(l,r)=maxdist(u,v),其中最大值取遍所有满足 l≤u,v≤r 的顶点对 (u,v)。
请计算 ∑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.
第一行包含一个整数 n(1≤n≤105)——树中顶点的数量。
接下来的 n−1 行描述树的边。每行包含两个整数 u,v(1≤u,v≤n)——对应树边的两个端点编号。保证所给边列表确实构成一棵树。
输出格式
Print a single integer — ∑1≤l≤r≤ndiam(l,r).
输出一个整数——∑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
输入解题思路,AI测评打分。不知道怎么写?