Bottleneck Paths
View as PDFYou are given a connected undirected graph with vertices and
weighted edges. For every
pair of vertices, find a path that minimizes the maximum edge weight along the path.
In other words, if ranges over all paths from
to
, the bottleneck is
.
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 bottleneck between
and
.
For every
, print
.
Constraints
Example 1
Input
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
Output
0 5 5 5
5 0 1 2
5 1 0 2
5 2 2 0
Explanation
Between and
, the direct edge has weight
, but the path
has maximum
edge
, which is better. Between
and
, the path
has
maximum edge
, which beats the direct edge of weight
.
Comments