Under construction

Still being built. Things may change

Tax

Time limit2sMemory limit1024 MB

Summary
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 nn cities and mm bidirectional roads in Byteland, labeled 1,2,…,n1,2,\dots,n. JB starts at city 11 and can only drive on these mm roads. Every city is always reachable from city 11.

The length of each road is the same, but each road is controlled by one of several engineering companies. For the ii-th road, the controlling company is cic_i. If this is the kk-th time JB drives on a road controlled by company tt, JB pays k×wtk\times w_t dollars in tax.

JB selects a destination city. If the destination is city kk, JB drives from city 11 to city kk 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 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}), the number of cities and the number of bidirectional roads.

The second line contains mm integers w1,w2,…,wmw_1,w_2,\dots,w_m (1≤wi≤10 0001\leq w_i\leq 10\,000), the base tax of each company.

Each of the next mm lines contains three integers uiu_i, viv_i, and cic_i (1≤ui,vi≤n1\leq u_i,v_i\leq n, ui≠viu_i\neq v_i, 1≤ci≤m1\leq c_i\leq m). This describes a bidirectional road between city uiu_i and city viv_i, controlled by company cic_i.

There is at most one road between any pair of cities, and JB can always drive to every other city.

Output

Print n−1n-1 lines. The kk-th line (1≤k≤n−11\leq k\leq n-1) contains one integer, the minimum number of dollars JB needs to pay when the destination is city k+1k+1.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    1
    9
    1
    3