题意
给定一个$n \times n$的矩阵A, $A_{i,j}$表示第$i$个点和第$j$个点之间的距离。同时有一些点的初始距离一开始不确定。
需要满以下几个条件
• the distance from a point to itself is zero,
• the distance between two distinct points is non-negative,
• the distance from A to B is the same as the distance from B to A, and
• the distance from A to B (directly) is less than or equal to the distance from A to B via any third point C, i.e., $d(A, B) ≤ d(A, C) + d(C, B)$.
问是否可以做到,如果可以,构造出这样一个矩阵出来
解法
将-1的点置为inf,然后跑一遍floyd。
最后check
- 自己和自己的距离是否为0
- $i$到$j$的距离是否等于$j$到$i$的距离
- 原始的点的距离是否被改变
1 |
|