#P5306. [COCI 2018/2019 #5] Transport
[COCI 2018/2019 #5] Transport
Description
A country has cities. Each city has a gas station with fuel supply .
There are roads connecting these cities into a tree structure.
For a truck to travel from city to city , the amount of fuel in the truck must be at least the distance between and .
Each time the truck arrives at a city, it can refuel by an amount not exceeding the fuel supply of that city's gas station.
Assume the truck's fuel tank has infinite capacity, and it consumes one unit of fuel for each kilometer traveled. Please calculate how many ordered pairs satisfy:
A truck whose initial fuel is can start from city , reach city , and .
Note that the truck can only travel along a simple path, meaning it cannot go back.
Input Format
The first line contains a positive integer .
The second line contains positive integers , representing the fuel supply of each gas station.
The next lines each contain three positive integers , indicating that there is a road of length between cities and .
Output Format
Output one integer in a single line, representing the answer.
2
3 1
1 2 2
1
5
3 1 2 4 5
1 2 3
3 2 2
4 2 6
5 4 3
5
Hint
Explanation for Sample 1:
The only feasible pair is , meaning only is feasible.
Constraints:
For of the testdata:
。
For of the testdata:
The tree is a chain.
For of the testdata:
。
。
。
Translated by ChatGPT 5
京公网安备 11011102002149号