Jewelery pieces

3.2

6 votes
Dynamic Programming, Algorithms, Trees
Problem

A country consists of n cities connected by (n1) multidimensional roads, where each road has length li meters. A group of friends want to purchase a jewelry piece.

There are m jewelry pieces in the country and each of them is located in some city ci and has a value vi. Each friend cannot walk for more than wi meters.

Your task is to determine the highest value of the jewelry piece that you can buy if a friend started walking from city 1 and returns to the same city after the purchase.

Input format

  • First line: Three integers n, m, and k denoting the number of cities, number of jewelry pieces, and number of friends
  • Second line: k integers wi denoting the number of meters the ith friend can walk
  • Each of the next n1 lines: Three integers aibi, and li denoting the road from city ai to city bi and length li meters 
  • Each of the next m lines: Two integers cj and vjdenoting the city that consists of the jewelry pieces and the value of each piece

Output format

Print k integers, where the ith value represents the highest value of jewelry piece that they bought. The ith friend can buy the jewelry piece if he or she started walking from city 1 and returned to the same city after the purchase.

Constraints

1n10001m1061k1061wi10001li10001vj109

Time Limit: 3
Memory Limit: 512
Source Limit:
Explanation
  • The first member can't go to any city and return to the first city so the totatl gain equals to the value of the first city whose value is 1.
  • The second member can go to the cities 2 and 3 then return back to the first city with total walked meters = 1 + 2 + 2 + 1 = 6 which is smaller than 10 and the total gain = 1 + 2 + 3 = 6.
  • The third and fourth members can go to all cities then return to the first city. 
Editor Image

?