#3218. 树

image

Samples

3
1
8
1000000000000000000
1
6
4 5
1 2
6 5
5 2
2 3
-1

image # image

image