Pondo Shortest Paths
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
3.0s
Python 3
3.0s
Memory limit:
500M
Problem type
You are given a connected undirected graph with vertices and
weighted edges. For every
pair of vertices, determine the shortest-path distance between them.
Input
The first line contains two space-separated integers and
.
Each of the next lines contains three integers
,
, and
, denoting an undirected edge
between
and
with weight
. There may be multiple edges between the same pair of
vertices, and there may be self-loops.
Vertices are numbered through
.
Output
Print lines. The
line should contain
space-separated integers
, where
is the shortest-path distance from
to
.
Constraints
Example 1
Input
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
Output
0 5 6 8
5 0 1 3
6 1 0 2
8 3 2 0
Comments