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

建议使用的浏览器:

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

6876:Jump

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

You are also given an array $a$ with $n$ elements.

Define $dep(x)$ as the sum of weight of edges on the simple path between $rt$ and $x$.

Define $fa(x)$ as the father of node $x$, especially, we define $fa(rt)=rt$.

There are $m$ operations of two types:

`1 l r`: for each $i$ that satisfies $l \le i \le r$, $a_i := fa(a_i)$.

`2 l r`: for each $i$ that satisfies $l \le i \le r$, output the minimum $dep(a_i)$.
输入解释
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 three integers $n,m,rt$.

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 which is $d$.

The next line contains $n$ integers, the ith integer is $a_i$.

For the following $m$ lines, each line contains three integers $opt,l,r$, which means that there is a operation of type $opt$ for $l,r$.

$1\le T \le 4$, $1\le n,m\le 2\cdot 10^5$, the weight of edge is an integer in range $[0,10^9]$.
输出解释
For each operation that $opt=2$, output one line representing the answer.
输入样例
4
5 1 5
2 5 4
1 5 4
3 2 1
4 2 3
3 4 3 2 5
2 3 3
6 2 1
6 1 1
2 1 1
4 2 3
5 4 2
3 2 1
2 3 6 1 2 6
2 4 6
2 3 3
5 1 5
4 5 3
2 4 2
1 4 2
3 5 3
1 1 5 2 5
2 2 2
5 4 3
2 3 1
1 2 4
5 2 2
4 5 4
1 4 1 1 4
2 2 5
1 1 5
2 2 2
1 1 4
输出样例
5
0
1
5
5
3
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6876

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

共提交 0

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