Tax
Time limit2sMemory limit1024 MB
Given roads where the k-th use of a company's road costs k times that company's tax, find the cheapest shortest path from city 1 to each other city.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, BFS, Dynamic programming
- Solved
- No attempts yet
Problem
JB received his driver's license recently. To celebrate this, JB decides to drive to other cities in Byteland. There are cities and bidirectional roads in Byteland, labeled . JB starts at city and can only drive on these roads. Every city is always reachable from city .
The length of each road is the same, but each road is controlled by one of several engineering companies. For the -th road, the controlling company is . If this is the -th time JB drives on a road controlled by company , JB pays dollars in tax.
JB selects a destination city. If the destination is city , JB drives from city to city along a shortest path. If several shortest paths exist, JB picks the one with the smallest total tax. Calculate the minimum total tax JB pays for each possible destination.
Input
The input contains only a single case.
The first line contains two integers and (, ), the number of cities and the number of bidirectional roads.
The second line contains integers (), the base tax of each company.
Each of the next lines contains three integers , , and (, , ). This describes a bidirectional road between city and city , controlled by company .
There is at most one road between any pair of cities, and JB can always drive to every other city.
Output
Print lines. The -th line () contains one integer, the minimum number of dollars JB needs to pay when the destination is city .