Under construction

Still being built. Things may change

Sirens

Time limit3sMemory limit1024 MB

Summary
Given a weighted tree where siren i activates every room within distance d_i, find the fewest sirens to turn on by hand so all sirens turn on.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, Graph, DFS
Solved
No attempts yet

Statement

An underground bunker has nn rooms connected by n−1n - 1 corridors. Each corridor joins two different rooms and has a fixed length. The bunker is built so that you can walk from any room ii to any other room jj. There is exactly one path between two rooms that does not use the same corridor twice. The sum of the lengths of the corridors on that path is called the distance between rooms ii and jj, written ρ(i,j)\rho(i, j).

Each room has a siren and a sound sensor that turns it on. A siren in room ii activates the sensor in every room jj with ρ(i,j)≤di\rho(i, j) \leq d_i, where did_i is the power of that siren. So turning on the siren in room ii automatically turns on the siren in every room jj with ρ(i,j)≤di\rho(i, j) \leq d_i. Each siren that turns on can in turn trigger other sirens, and so on.

In an emergency, some sirens must be turned on by hand. Their sound then turns on the sirens in other rooms automatically. Safety rules require choosing a set of sirens to turn on by hand so that, in the end, the sirens in all rooms turn on automatically.

Write a program that finds the minimum number of sirens in a set that satisfies the safety rules.

Input

The first line contains one integer nn, the number of rooms.

The second line contains nn integers d1,d2,…,dnd_1, d_2, \ldots, d_n, where did_i is the maximum distance at which the siren in room ii activates the sensors (0≤di≤1090 \leq d_i \leq 10^9).

Each of the next n−1n - 1 lines describes a corridor with three integers uiu_i, viv_i, lil_i. Here uiu_i and viv_i are the numbers of the two different rooms connected by corridor ii, and lil_i is the length of that corridor (1≤ui,vi≤n1 \leq u_i, v_i \leq n; 1≤li≤1091 \leq l_i \leq 10^9).

Output

Print one integer, the minimum number of sirens that must be turned on by hand.

Constraints

1≤n≤300 0001 \leq n \leq 300\,000

Hint

In the sample test, the siren in room 4 turns on the siren in room 5, which in turn turns on the sirens in rooms 6 and 7. The siren in room 2 turns on the siren in room 3. The siren in room 8 turns on the sirens in rooms 1, 9, and 10.

Examples1

  1. Example 1

    Input
    10
    1 2 2 2 6 3 4 5 4 3
    1 2 5
    2 3 1
    2 4 5
    4 5 2
    4 6 4
    4 7 3
    1 8 1
    8 9 5
    8 10 4
    
    Expected output
    3