Bottleneck Paths
You are given a connected undirected graph with n vertices and m weighted edges. For every pair of vertices, find a path that minimizes the maximum edge weight along the path.
In other words, if P ranges over all paths from u to v, the bottleneck is
minPmaxe∈Pw(e).
Input
The first line contains two space-separated integers n and m.
Each of the next m lines contains three integers u, v, and w, denoting an undirected edge between u and v with weight w. There may be multiple edges between the same pair of vertices, and there may be self-loops.
Vertices are numbered 1 through n.
Output
Print n lines. The ith line should contain n space-separated integers ai,1,ai,2,…,ai,n, where au,v is the bottleneck between u and v. For every u, print au,u=0.
Constraints
- 1≤n≤100
- 1≤m≤2n⋅(n−1)
- 1≤u,v≤n
- 1≤w≤109
Example 1
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
0 5 5 5
5 0 1 2
5 1 0 2
5 2 2 0
Explanation
Between 1 and 3, the direct edge has weight 9, but the path 1→2→3 has maximum edge max(5,1)=5, which is better. Between 2 and 4, the path 2→3→4 has maximum edge 2, which beats the direct edge of weight 3.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.