menu ZJOJ
account_circle 请登录
home
首页
book
题目
apps
分类
play_circle_outline
状态
assessment
竞赛
assignment
作业
equalizer
排名
assignment_ind
登录
person_add
注册
1571: Floyd
时间限制:1.000s
内存限制:128MB

题目描述

给出一张由 lns="http://www.w3.org/1998/Math/MathML">n 个点 lns="http://www.w3.org/1998/Math/MathML">m 条边组成的无向图。

求出所有点对 lns="http://www.w3.org/1998/Math/MathML">(i,j) 之间的最短路径。

输入格式

第一行为两个整数 lns="http://www.w3.org/1998/Math/MathML">n,m,分别代表点的个数和边的条数。

接下来 lns="http://www.w3.org/1998/Math/MathML">m 行,每行三个整数 lns="http://www.w3.org/1998/Math/MathML">u,v,w,代表 lns="http://www.w3.org/1998/Math/MathML">u,v 之间存在一条边权为 lns="http://www.w3.org/1998/Math/MathML">w 的边。

输出格式

输出 lns="http://www.w3.org/1998/Math/MathML">n 行每行 lns="http://www.w3.org/1998/Math/MathML">n 个整数。

第 lns="http://www.w3.org/1998/Math/MathML">i 行的第 lns="http://www.w3.org/1998/Math/MathML">j 个整数代表从 lns="http://www.w3.org/1998/Math/MathML">i 到 lns="http://www.w3.org/1998/Math/MathML">j 的最短路径。

样例输入 content_copy

4 4
1 2 1
2 3 1
3 4 1
4 1 1

样例输出 content_copy

0 1 2 1
1 0 1 2
2 1 0 1
1 2 1 0

提示/说明

对于 lns="http://www.w3.org/1998/Math/MathML">100\% 的数据,lns="http://www.w3.org/1998/Math/MathML">n \le 100lns="http://www.w3.org/1998/Math/MathML">m \le 4500,任意一条边的权值 lns="http://www.w3.org/1998/Math/MathML">w 是正整数且 lns="http://www.w3.org/1998/Math/MathML">1 \leqslant w \leqslant 1000

数据中可能存在重边。

分类