Perry the Pirate is sailing the seven seas! He has a map consisting of islands connected by a network of sea routes. The -th sea route connects islands and and costs coins to traverse in either direction. As it turns out, fighting off sea monsters can be quite expensive. In search of his next big plunder, Perry has scouted out each of the islands and has determined that the -th island contains a treasure chest with coins inside.

It remains for him to plan out his next journey. He decides that he will sail through some (possibly empty) path of sea routes starting at island and ending at island . At the end of his journey, he will open the chest at island and collect his well-earned booty.

There is one small problem though: Perry doesn't know what island he's currently on! Thus, for every possible starting island , he would like to know the maximum possible number of coins he can earn out of all journeys starting at island . Can you help him compute these values? You may assume Perry has enough coins to traverse any path of sea routes he chooses; he only cares about the net profit of his next journey.

#### Input Specification

The first line of input contains two space-separated integers and .

The second line of input contains space-separated integers .

The next lines each contain three space-separated integers , and .

It is guaranteed that there is at most one sea route between any pair of islands and each sea route connects two distinct islands.

Marks | Awarded | Bounds on N | Bounds on M | Additional constraints |
---|---|---|---|---|

5 | marks | None | ||

5 | marks | For all , either or | ||

7 | marks | Exactly one path of sea routes between any pair of islands | ||

8 | marks | None |

#### Output Specification

Output lines, where the -th line contains the maximum possible net profit (in coins) of any journey starting at island .

#### Sample Input 1

```
4 5
6 5 9 2
1 2 0
3 2 3
4 3 6
1 3 5
2 4 2
```

#### Sample Output 1

```
6
6
9
4
```

#### Explanation for Sample 1

For the first and third islands, it is best to just stay and open the chest on the island itself.

For the second island, Perry can travel to the first island and open the chest there.

This has a net profit of coins and is the best possible net profit.

For the fourth island, Perry can travel to the second and then the third island and open the chest there.

This has a net profit of coins and is the best possible net profit.

## Comments

:(

Is there an editorial

https://cemc.uwaterloo.ca/resources/past-contests?grade=All&academic_year=All&contest_category=80. These are 2024 CCO solutions posted by the CEMC. Please refer to these. If you have more questions, you can join the DMOJ Discord server for more help.

.