「Codeforces 938D」Buy a Ticket【最短路】

Time Limit: 2 Sec Memory Limit: 512 MB

Description

Musicians of a popular band “Flayer” have announced that they are going to “make their exit” with a world tour. Of course, they will visit Berland as well.

There are $n$ cities in Berland. People can travel between cities using two-directional train routes; there are exactly $m$ routes, the $i$-th route can be used to go from city $v_i$ to city $u_i$ (and from $u_i$ to $v_i$), and it costs $w_i$ coins to use this route.

Each city will be visited by “Flayer”, and the cost of the concert ticket in the $i$-th city is $a_i$ coins.

You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city $i$ you have to compute the minimum number of coins a person from city $i$ has to spend to travel to some city $j$ (or possibly stay in city $i$), attend a concert there, and return to city $i$ (if $j \neq i$).

Formally, for every $i \in [1, n]$ you have to calculate $\displaystyle \min_{j=1}^n 2d(i, j) + a_j$, where d(i, j) is the minimum number of coins you have to spend to travel from city $i$ to city $j$. If there is no way to reach city $j$ from city $i$, then we consider d(i, j) to be infinitely large.

Input

The first line contains two integers $n$ and $m$ ($2 \leqslant n \leqslant 2 \cdot 10^5$, $1 \leqslant m \leqslant 2 \cdot 10^5$).

Then $m$ lines follow, the $i$-th line contains three integers $v_i$, $u_i$ and $w_i$ ($1 \leqslant v_i, u_i \leqslant n$, $v_i \neq u_i$, $1 \leqslant w_i \leqslant 10^{12}$) denoting the $i$-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each $(v, u)$ neither extra $(v, u)$ nor $(u, v)$ present in input.

The next line contains $n$ integers $a_1, a_2, \cdots a_k$ ($1 \leqslant a_i \leqslant 10^{12}$) — price to attend the concert in the $i$-th city.

Output

Print $n$ integers. The $i$-th of them must be equal to the minimum number of coins a person from city $i$ has to spend to travel to some city $j$ (or possibly stay in city $i$), attend a concert there, and return to city $i$ (if $j \neq i$).

Solution

• 建立超级源点 $0$
• 对于每条边 $u_i \rightarrow v_i$，将距离乘以 $2$ 后加入。
• 对于权值 $a_i$，从源点 $0$ 向点 $i$ 连接一条权值为 $a_i$ 的边。