Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Chocolate

Problem Description
H.B. Inc. (Halim Bros.), one of the biggest chocolate providers in Loveland, plans to set up
some new shops before Valentines Day. These shops should be able to cover the whole Loveland.
Loveland is made up of several small towns. Towns are connected by expressways. The
expressway system is designed in such a way that there is exact one path between different

towns.
If there is a chocolate shop in the town, people will buy chocolate there. If not, they will
have to go outside to buy chocolate. However, a recent survey reveals that people in town K
never go to a chocolate shop over D(K) distance away.
Setting up chocolate shop in different towns cost differently. It is known that setting up a
shop in city K cost C(K). As we mentioned early, the company plans to cover the whole island.
Obviously, they do not want to spend too much. However, they find it a difficult job to calculate
the budget. Now they hire you to solve the problem for them. Can you tell them the smallest
cost to cover the whole Loveland?

Input
The first line of the input file contains an integer N , denoting the number of towns in Loveland. The second line contains N numbers separated by one or more blanks. The I -th number
denotes C(I) (1 C(I) 10000). The third line contains N numbers separated by one or more
blanks. The I -th number denotes D(I) (0 D(I) 10000). Then N 1 lines follows. Each contains three integers u, v, L (1 u, v N , 1 L 1000), which means there is an expressway
between town u and v of length L.
For 40% of the test data, 1 N 50.
For 100% of the test data, 1 N 1000.

Output
Output the minimum cost on a single line.

Sample Input
Sample 1:
5
11111
21112
121
231
341
451
Sample 2:
5
11311
21112
121
231
341
451

Sample Output
Output of Sample 1:
1
Output of Sample 2:
2

You might also like