Pondo Shortest Paths
You are given a connected undirected graph with n vertices and m weighted edges. For every pair of vertices, determine the shortest-path distance between them.
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 shortest-path distance from u to v.
Constraints
- 1≤n≤100
- 1≤m≤2n⋅(n−1)
- 1≤u,v≤n
- 1≤w≤100
Example 1
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
0 5 6 8
5 0 1 3
6 1 0 2
8 3 2 0
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.