Time Limit: 2 Sec Memory Limit: 512 MB
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 cities in Berland. People can travel between cities using two-directional train routes; there are exactly routes, the -th route can be used to go from city to city (and from to ), and it costs coins to use this route.
Each city will be visited by “Flayer”, and the cost of the concert ticket in the -th city is 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 you have to compute the minimum number of coins a person from city has to spend to travel to some city (or possibly stay in city ), attend a concert there, and return to city (if ).
Formally, for every you have to calculate , where d(i, j) is the minimum number of coins you have to spend to travel from city to city . If there is no way to reach city from city , then we consider d(i, j) to be infinitely large.
The first line contains two integers and (, ).
Then lines follow, the -th line contains three integers , and (, , ) denoting the -th train route. There are no multiple train routes connecting the same pair of cities, that is, for each neither extra nor present in input.
The next line contains integers () — price to attend the concert in the -th city.
Print integers. The -th of them must be equal to the minimum number of coins a person from city has to spend to travel to some city (or possibly stay in city ), attend a concert there, and return to city (if ).
Sample Input #1:
Sample Output #1:
- 建立超级源点 。
- 对于每条边 ，将距离乘以 后加入。
- 对于权值 ，从源点 向点 连接一条权值为 的边。
最后用 算法从源点 运行一遍最短路即可，点 的答案就是源点 到点 的距离。
技巧：本题使用 priority_queue 会超时，需使用 set 才能通过，因为 set 的时间复杂度为 且本题中的边数量较多。