Under construction

Still being built. Things may change

Treasure Hunt

Interview

Time limit4sMemory limit1024 MB

Summary
For each island x, find the maximum of v_y minus the cheapest sea route cost from x to any island y.
Level

Medium5 of 10

Topics
Graph, Shortest path
Solved
No attempts yet

Problem

Perry the Pirate is sailing the seven seas! He has a map consisting of NN islands connected by a network of MM sea routes. The ii-th sea route connects islands aia_i and bib_i and costs cic_i coins to traverse in either direction. Fighting off sea monsters is expensive. Perry has scouted each of the NN islands and found that the ii-th island has a treasure chest with viv_i coins inside.

Next, he plans his journey. He sails along some (possibly empty) path of sea routes that starts at island xx and ends at island yy. At the end, he opens the chest at island yy and collects the booty.

There is one problem. Perry does not know which island he is on. For every possible starting island xx, he wants the maximum number of coins he can earn over all journeys starting at island xx. You may assume Perry has enough coins to traverse any path he chooses. He only cares about the net profit of the journey.

Input

The first line contains two space-separated integers NN and MM.

The second line contains NN space-separated integers v1,v2,…,vNv_1, v_2, \ldots, v_N (0≤vi≤1090 \le v_i \le 10^9).

The next MM lines each contain three space-separated integers aia_i, bib_i (1≤ai,bi≤N1 \le a_i, b_i \le N), and cic_i (0≤ci≤1090 \le c_i \le 10^9). There is at most one sea route between any pair of islands, and each sea route connects two distinct islands.

Output

Output NN lines. The xx-th line contains the maximum net profit (in coins) of any journey starting at island xx.

Examples1

  1. Example 1

    Input
    4 5
    6 5 9 2
    1 2 0
    3 2 3
    4 3 6
    1 3 5
    2 4 2
    
    Expected output
    6
    6
    9
    4