Tax
시간 제한2초메모리 제한1024 MB
1번 도시에서 각 도시까지 최단 경로로 이동하되, 같은 회사 도로를 k번째 이용할 때 k 곱하기 기본 요금을 내는 조건에서 최소 세금을 구한다.
문제
JB received his driver's license recently. To celebrate this fact, JB decides to drive to other cities in Byteland. There are cities and bidirectional roads in Byteland, labeled by . JB is at the -st city, and he can only drive on these roads. It is always possible for JB to reach every city in Byteland.
The length of each road is the same, but they are controlled by different engineering companies. For the -th edge, it is controlled by the -th company. If it is the -th time JB drives on an edge controlled by the -th company, JB needs to pay dollars for tax.
JB is selecting his destination city. Assume the destination is the -th city, he will drive from city to city along the shortest path, and minimize the total tax when there are multiple shortest paths. Please write a program to help JB calculate the minimum number of dollars he needs to pay for each possible destination.
입력
The input contains only a single case.
The first line of the input contains two integers and (, ), denoting the number of cities and the number of bidirectional roads.
The second line contains integers (), denoting the base tax of each company.
In the next lines, the -th line contains three integers and (, , ), denoting denoting an bidirectional road between the -th city and the -th city, controlled by the -th company.
It is guaranteed that there are at most one road between a pair of city, and it is always possible for JB to drive to every other city.
출력
Print lines, the -th () of which containing an integer, denoting the minimum number of dollars JB needs to pay when the destination is the -th city.