| Almaty Code Cup 2024 |
|---|
| Finished |
Recently, Maxim flew to Korea and wanted to attend the fireworks festival in Busan.
The Korean train system is represented by a tree of $$$n$$$ vertices. Train routes are bidirectional, and each trip requires $$$1$$$ ticket.
Maxim starts his journey from vertex $$$1$$$ and needs to reach vertex $$$n$$$. While at vertex $$$i$$$, he can buy any number of tickets for $$$a_i$$$ won.
Find the minimum number of won needed for Maxim to reach vertex $$$n$$$ from vertex $$$1$$$.
The first line contains the number $$$n$$$ $$$(2 \leq n \leq 2\cdot 10^{5})$$$ — the number of vertices in the tree.
The second line contains $$$n$$$ numbers — the array $$$a$$$ $$$(1 \leq a_i \leq 10^6)$$$. $$$a_i$$$ — the price of one ticket at vertex $$$i$$$.
The next $$$n-1$$$ lines contain $$$2$$$ numbers each: $$$v_i, u_i$$$ — the ends of the train routes.
Output the minimum amount of money needed for Maxim to reach vertex $$$n$$$ from vertex $$$1$$$.
6100 10 5 4 100 101 22 33 41 55 6
130
78 1 5 7 9 4 31 21 32 43 51 62 7
9
91000 100 30 100 10 1000 1000 1000 101 22 32 44 51 66 77 88 9
1260
| Name |
|---|


