t is valid, if you can divide the. B, so that the following condition would hold:. You need to find out whether the node
You are given a tree of
n
n nodes, the i-th node has value
a_i
a
i
.
Define a node
t
t is valid, if you can divide the
n
n nodes into two sets
A
A and
B
B, so that the following condition would hold:
forall u,vin A(uneq v)
∀u,v∈A(u
=v), if
u
u is on the path from
t
t to
v
v, then
a_u
(图片来源网络,侵删)