Copy Paste 3???


You are given a directed graph with nn nodes and mm edges. What is the shortest-path distance from node 11 to every other node?

Input

The first line contains the integers nn and mm.

The following mm lines contain integers aa, bb, and cc indicating a directed edge from node aa to node bb with weight cc. There may be multiple edges between the same pair of nodes.

The nodes are numbered 11 through nn.

It is guaranteed that there is a path from 11 to every other node and that there are no negative cycles.

Output

Print one line with n1n - 1 integers: the shortest-path distances to nodes 22, 33, \ldots, nn, in that order, separated by spaces.

Constraints

  • 2n10002 \le n \le 1000
  • 1m50001 \le m \le 5000
  • 1a,bn1 \le a, b \le n
  • 109c109-10^9 \le c \le 10^9

Example 1

Input 1
3 3
1 2 2
1 3 1
3 2 -1
Output 1
0 1
Explanation

The shortest path to node 33 is the direct edge of weight 11. The shortest path to node 22 is 1321 \to 3 \to 2 with total weight 00.

Example 2

Input 2
10 15
1 2 7
2 3 7
3 4 4
4 5 6
5 6 3
6 7 8
7 8 9
8 9 8
9 10 5
10 1 1
8 10 3
4 6 1
6 9 2
4 5 3
6 10 3
Output 2
7 14 18 21 19 27 36 21 22

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.