Bottleneck Paths


You are given a connected undirected graph with nn vertices and mm weighted edges. For every pair of vertices, find a path that minimizes the maximum edge weight along the path.

In other words, if PP ranges over all paths from uu to vv, the bottleneck is

min⁡Pmax⁡e∈Pw(e)\min_P \max_{e \in P} w(e).

Input

The first line contains two space-separated integers nn and mm.

Each of the next mm lines contains three integers uu, vv, and ww, denoting an undirected edge between uu and vv with weight ww. There may be multiple edges between the same pair of vertices, and there may be self-loops.

Vertices are numbered 11 through nn.

Output

Print nn lines. The ithi^{th} line should contain nn space-separated integers ai,1,ai,2,…,ai,na_{i,1}, a_{i,2}, \ldots, a_{i,n}, where au,va_{u,v} is the bottleneck between uu and vv. For every uu, print au,u=0a_{u,u} = 0.

Constraints

  • 1≤n≤1001 \le n \le 100
  • 1≤m≤n⋅(n−1)21 \le m \le \frac{n \cdot (n - 1)}{2}
  • 1≤u,v≤n1 \le u, v \le n
  • 1≤w≤1091 \le w \le 10^9

Example 1

Input 1
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
Output 1
0 5 5 5
5 0 1 2
5 1 0 2
5 2 2 0
Explanation

Between 11 and 33, the direct edge has weight 99, but the path 1→2→31 \to 2 \to 3 has maximum edge max⁡(5,1)=5\max(5, 1) = 5, which is better. Between 22 and 44, the path 2→3→42 \to 3 \to 4 has maximum edge 22, which beats the direct edge of weight 33.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.