FarmCraft
Time limit3sMemory limit256 MB
Choose a tour of the tree from the root that visits every house and returns, so the latest moment of arrival plus install time is as early as possible.
Problem
The village of Byteville has houses joined by roads. Between any two houses there is exactly one route. The houses are numbered from to , and house belongs to Byteasar, who runs the village.
A rural technology programme has delivered computers to Byteasar's house. Every house gets one computer, and Byteasar has to hand them out. The villagers have already agreed to start the latest version of FarmCraft together as soon as they have their machines.
Byteasar loads all the computers onto his pickup truck and sets off. He has exactly enough fuel to drive along each road twice. When he reaches a house he drops off one computer and drives on immediately. A household starts installing FarmCraft the moment its computer arrives. The install time differs from house to house and is known in advance. Byteasar installs the game on his own computer only after he has delivered everything and driven back home. Driving along one road takes minute, and unloading a computer takes no time.
Find the earliest moment at which every villager, Byteasar included, can start playing. That is, choose the delivery order that makes the last install finish as early as possible, and report that finishing time.
Input
The first line contains the number of houses in Byteville, . ()
The second line contains the integers separated by single spaces. is the install time in minutes for house . ()
Each of the next lines describes one road. Such a line contains two integers and separated by a single space (), meaning that a road runs directly between house and house .
Output
Print one integer on the first line: the earliest time, in minutes, at which the install has finished in every house, Byteasar's included.
Note
The picture below shows the village from the example.

If Byteasar delivers the computers in the order and then drives home, the installs in houses to finish after minutes. Everyone starts playing after minutes.
If he delivers them in the order , the installs finish after minutes, so nobody can start together until minutes have passed.