当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6874:Distance

题目描述
You are given a tree with $n$ nodes, each edge of the tree has a weight, the nodes of the tree are numbered from $1$ to $n$.

Let $\texttt {dist}(i,j)$ be the sum of edges' weight on the path between $i$ and $j$.

You need to answer $m$ queries, each query is given $l,r$, you are asked to output the sum of all $\texttt {dist}(i,j)$, that satisfies $l \le i<j \le r$.
输入解释
The input contains several test cases, and the first line contains a single integer $T$, the number of test cases.

For each test case:

The first line contains two integers $n,m$.

For the following $n-1$ lines, each line contains three integers $u,v,d$, which means that there is an edge between $u,v$, the weight of this edge is $d$.

For the following $m$ lines, each line contains two integers $l,r$, which means that there is a query for $l,r$.

$1 \le T \le 3$,$1\le n,m,d\le 2\cdot 10^5$, $l \le r$, all input are integers.
输出解释
For each test case, output $m$ lines representing the answer for the given $m$ queries.

You need to output the answer module $2^{32}$.
输入样例
3
6 6
2 1 1
5 1 1
3 1 3
4 5 1
6 3 3
2 5
1 5
1 4
3 6
2 6
1 1
6 6
2 1 3
3 1 2
4 3 1
5 1 1
6 3 3
2 4
2 4
1 1
1 6
1 4
1 1
6 6
6 5 2
1 6 3
4 1 1
3 5 2
2 4 3
5 5
1 3
1 1
3 4
4 5
1 1
输出样例
19
26
18
28
44
0
12
12
0
58
20
0
0
22
0
8
6
0
来自杭电HDUOJ的附加信息
Recommend IceyWang

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6874

最后修改于 2020-10-25T23:35:08+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
15000/15000MS(Java/Others) 524288/524288K(Java/Others)