Perry the Pirate is sailing the seven seas!
He has a map consisting of
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
There is one small problem though: Perry doesn't know what island he's currently on!
Thus, for every possible starting island
Input Specification
The first line of input contains two space-separated integers
The second line of input contains
The next
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 |
||
7 marks | Exactly one path of sea routes between any pair of islands | ||
8 marks | None |
Output Specification
Output
Sample Input
4 5
6 5 9 2
1 2 0
3 2 3
4 3 6
1 3 5
2 4 2
Sample Output
6
6
9
4
Explanation for Sample

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
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
Comments
:(
Is there an editorial
This comment is hidden due to too much negative feedback. Show it anyway.
.