#cf17finalj. [cf17_final_j]Tree MST

[cf17_final_j]Tree MST

Problem Statement

Ringo has a tree with NN vertices. The ii-th of the N1N-1 edges in this tree connects Vertex AiA_i and Vertex BiB_i and has a weight of CiC_i. Additionally, Vertex ii has a weight of XiX_i.

Here, we define f(u,v)f(u,v) as the distance between Vertex uu and Vertex vv, plus Xu+XvX_u + X_v.

We will consider a complete graph GG with NN vertices. The cost of its edge that connects Vertex uu and Vertex vv is f(u,v)f(u,v). Find the minimum spanning tree of GG.

Constraints

  • 2leqNleq200,0002 \\leq N \\leq 200,000
  • 1leqXileq1091 \\leq X_i \\leq 10^9
  • 1leqAi,BileqN1 \\leq A_i,B_i \\leq N
  • 1leqCileq1091 \\leq C_i \\leq 10^9
  • The given graph is a tree.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN X1X_1 X2X_2 ...... XNX_N A1A_1 B1B_1 C1C_1 A2A_2 B2B_2 C2C_2 :: AN1A_{N-1} BN1B_{N-1} CN1C_{N-1}

Output

Print the cost of the minimum spanning tree of GG.


Sample Input 1

4
1 3 5 1
1 2 1
2 3 2
3 4 3

Sample Output 1

22

We connect the following pairs: Vertex 11 and 22, Vertex 11 and 44, Vertex 33 and 44. The costs are 55, 88 and 99, respectively, for a total of 2222.


Sample Input 2

6
44 23 31 29 32 15
1 2 10
1 3 12
1 4 16
4 5 8
4 6 15

Sample Output 2

359

Sample Input 3

2
1000000000 1000000000
2 1 1000000000

Sample Output 3

3000000000