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≤i≤r![]()
,
a
i
:=fa(a
i
)![]()
.
`2 l r`: for each
i![]()
that satisfies
l≤i≤r![]()
, output the minimum
dep(a
i
)![]()
.