Types: N: int, A: List[int], U: List[int], V: List[int]
Ranges: 1 ≤ N ≤ 5000, 1 ≤ |A_i| ≤ 10^9 (1 ≤ i ≤ N), 1 ≤ U_i, V_i ≤ N (1 ≤ i ≤ N - 1)
Addtl Info: U_i ≠ V_i (1 ≤ i ≤ N - 1), Any two different devices are connected through some number of cables.