Limits 1s, 512 MB

Bob wants to visit a new country called sayadpur. There are NN cities (1,2,3,,N1, 2, 3, …, N) in sayadpur, and they are connected by N1N-1 undirected roads. You can go from one city to any other city using these roads. Each city except city 1 is directly connected with at most two cities. Bob wants to start his journey from a city and then move to any adjacent city. In his journey, he does not want to visit a city twice. For visiting a city he has to pay a cost. Suppose he visits total kk cities and the cost of those cities are a1,a2,,aka_1,a_2, …, a_k.

The overall cost will be the bitwise “or” of those costs (a1a2a3aka_1 | a_2 | a_3 | … | a_k). You have to find the maximum overall cost.

Input

First-line there is a number NN ( 1N1051 ≤ N ≤ 10^5 ).

Each of the next N1N-1 lines contains two integers uu and vv (1u,vn1 ≤ u, v ≤ n and uvu≠v), denoting an edge connecting vertex uu and vertex vv. Next line contains NN integers a1,a2,,aNa_1, a_2, …, a_N (1ai20471 ≤ a_i ≤ 2047 and 1iN1 ≤ i ≤ N). The first element is the cost of city number 1, the second element is the cost of city number 2 city and so on.

Output

Output one integer, the maximum overall cost.

Sample

InputOutput
3
1 2
1 3
1 2 4
7

Submit

Login to submit.

Contributors

Statistics

71% Solution Ratio
YouKnowWhoEarliest, Aug '20
user12345Fastest, 0.0s
helium_00Lightest, 6.5 MB
zishan044Shortest, 626B
Toph uses cookies. By continuing you agree to our Cookie Policy.