Bob wants to visit a new country called sayadpur. There are cities () in sayadpur, and they are connected by 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 cities and the cost of those cities are .
The overall cost will be the bitwise “or” of those costs (). You have to find the maximum overall cost.
First-line there is a number ( ).
Each of the next lines contains two integers and ( and ), denoting an edge connecting vertex and vertex . Next line contains integers ( and ). 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 one integer, the maximum overall cost.
Input | Output |
---|---|
3 1 2 1 3 1 2 4 | 7 |