After their success at Adham and Halzoom's mill, the friends found themselves at the foot of an enormous, ancient tree, unlike any they had seen. Its branches spiraled upwards into the misty canopy, forming a complex, sprawling network. Abd-Elmohaymen, ever the one to explore, recognized it as a legendary "Whispering Tree," said to hold the secrets of the forest in its very structure.
A shimmering inscription appeared on its gnarled trunk: "To find the truest path within, from root to leaf, a number win. Walk but one way, from top to floor, and values join, to ask for more. Build with digits, what you find, the largest number, of its kind."
It explained that the tree was rooted at node 0. Each node had a unique 'spirit value' (a single digit from 1 to 9). They were allowed to choose two nodes and take the shortest path between them. As they walked, they had to collect the spirit value of each node they visited, adding it to an empty sequence. Once they reached a leaf node, this sequence of collected digits would form a large number.
Sam07a immediately understood: they needed to find the path that, when its node values were concatenated, would form the largest possible number. Omar worried about the sheer number of paths, while Abd-Elmohaymen was determined to find the "truest" (and largest) number hidden within the tree's whispers. They knew they couldn't delete or reorder any digits – the path defined the number.
The example diagram showed a path from node 1 (green) to node 5 (red) forming the number 95928, which was the largest for that small tree. The tree in front of them, however, was massive, though its height (depth) didn't seem to exceed 150 levels.
Help Sam07a, Omar, and Abd-Elmohaymen find the largest number they can obtain by traversing a single path in the Whispering Tree.
Illustration of the first sample case. The first line will contain the number of nodes $$$n$$$ $$$(1 \le n \le 5*10^5)$$$.
The second line will contain $$$n$$$ values $$$a_i(1 \le a_i \le 9 , 0 \le i \le n-1 )$$$ where $$$a_i$$$ is the value of the $$$ith$$$ node.
The next $$$n-1$$$ lines contain two integers $$$u$$$ , $$$v$$$ $$$(0 \le u,v \le n-1)$$$ indicating an edge between $$$u$$$ and $$$v$$$.
Output the largest number you can obtain.
6 5 9 3 9 2 8 0 1 0 2 0 3 3 4 4 5
95928
| Name |
|---|


