#icpc2016autumnk. [icpc2016autumn_k]Non-redundant Drive

[icpc2016autumn_k]Non-redundant Drive

MathJax.Hub.Config({ tex2jax: { inlineMath: [["","",""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }

Problem Statement

The people of JAG kingdom hate redundancy. For example, the NN cities in JAG kingdom are connected with just N1N-1 bidirectional roads such that any city is reachable from any city through some roads. Under the condition, the number of paths from a city to another city is exactly one for all pairs of the cities. This is a non-redundant road network :)

One day, you, a citizen of JAG kingdom, decided to travel as many cities in the kingdom as possible with a car. The car that you will use has an infinitely large tank, but initially the tank is empty. The fuel consumption of your car is 1 liter per 1 km, i.e. it consumes 1 liter of gasoline to move 1 km.

Each city has exactly one gas station, and you can supply g_xg\_x liters of gasoline to your car at the gas station of the city xx. Of course, you have a choice not to visit some of the gas stations in your travel. But you will not supply gasoline twice or more at the same gas station, because it is redundant. Each road in the kingdom has a distance between two cities: the distance of ii-th road is d_id\_i km. You will not pass the same city or the same road twice or more, of course, because it is redundant.

If a quantity of stored gasoline becomes zero, the car cannot move, and hence your travel will end there. But then, you may concern about an initially empty tank. Don't worry. You can start at any gas station of the cities in the kingdom. Furthermore, each road directly connects the gas stations of the its two ends (because the spirit of non-redundancy avoids redundant moves in a city), you therefore can supply gasoline to your car even if your car tank becomes empty just when you arrive the city.

Your task is to write a program computing the maximum number of cities so that you can travel under your non-redundancy policy.


Input

The input consists of a single test case.

NN
g_1g\_1g_Ng\_N
a_1a\_1 b_1b\_1 d_1d\_1

a_N1a\_{N-1} b_N1b\_{N-1} d_N1d\_{N-1}

The first line contains an integer NN (1leNle100,0001 \\le N \\le 100{,}000), which is the number of cities in JAG kingdom. The second line contains NN integers: the ii-th of them is g_ig\_i (1leg_ile10,0001 \\le g\_i \\le 10{,}000), the amount of gasoline can be supplied at the gas station of the city ii. The following N1N-1 lines give information of roads: the jj-th line of them contains a_ja\_j and b_jb\_j, which indicates that the jj-th road bidirectionally connects the cities a_ja\_j and b_jb\_j (1lea_j,b_jleN1 \\le a\_j, b\_j \\le N, a_jneb_ja\_j \\ne b\_j) with distance d_jd\_j (1led_jle10,0001 \\le d\_j \\le 10{,}000). You can assume that all cities in the kingdom are connected by the roads.

Output

Print the maximum number of cities you can travel from any city under the constraint such that you can supply gasoline at most once per a gas station.



Sample Input 1

5
5 8 1 3 5
1 2 4
2 3 3
2 4 3
1 5 7```

### Output for the Sample Input 1

```plain
4```

* * *

### Sample Input 2

```plain
2
10 1
1 2 10```

### Output for the Sample Input 2

```plain
2```

* * *

### Sample Input 3

```plain
5
1 3 5 1 1
1 2 5
2 3 3
2 4 3
1 5 5```

### Output for the Sample Input 3

```plain
3```

* * *