Tax

시간 제한2초메모리 제한1024 MB

요약
1번 도시에서 각 도시까지 최단 경로로 이동하되, 같은 회사 도로를 k번째 이용할 때 k 곱하기 기본 요금을 내는 조건에서 최소 세금을 구한다.
난이도

어려움10점 중 8점

유형
최단 경로, 그래프, 동적 계획법
정답자
아직 제출이 없습니다

문제

JB received his driver's license recently. To celebrate this fact, JB decides to drive to other cities in Byteland. There are nn cities and mm bidirectional roads in Byteland, labeled by 1,2,…,n1,2,\dots,n. JB is at the 11-st city, and he can only drive on these mm 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 ii-th edge, it is controlled by the c_ic\_i-th company. If it is the kk-th time JB drives on an edge controlled by the tt-th company, JB needs to pay k×w_tk\times w\_t dollars for tax.

JB is selecting his destination city. Assume the destination is the kk-th city, he will drive from city 11 to city kk 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 nn and mm (2≤n≤502 \leq n\leq 50, n−1≤m≤n(n−1)2n-1\leq m \leq \frac{n(n-1)}{2}), denoting the number of cities and the number of bidirectional roads.

The second line contains mm integers w_1,w_2,…,w_mw\_1,w\_2,\dots,w\_m (1≤w_i≤10,0001\leq w\_i\leq 10\\,000), denoting the base tax of each company.

In the next mm lines, the ii-th line (1≤i≤m)(1 \le i \le m) contains three integers u_i,v_iu\_i,v\_i and c_ic\_i (1≤u_i,v_i≤n1\leq u\_i,v\_i\leq n, u_i≠v_iu\_i\neq v\_i, 1≤c_i≤m1\leq c\_i\leq m), denoting denoting an bidirectional road between the u_iu\_i-th city and the v_iv\_i-th city, controlled by the c_ic\_i-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 n−1n-1 lines, the kk-th (1≤k≤n−11\leq k\leq n-1) of which containing an integer, denoting the minimum number of dollars JB needs to pay when the destination is the (k+1)(k+1)-th city.

예제1

  1. 예제 1

    입력
    5 6
    1 8 2 1 3 9
    1 2 1
    2 3 2
    1 4 1
    3 4 6
    3 5 4
    4 5 1
    
    예상 출력
    1
    9
    1
    3