All-Pairs Shortest Paths
2026/3/9小于 1 分钟
All-Pairs Shortest Paths
题面
实现 Floyd–Warshall:对 N×N 距离矩阵(行优先,+∞ 表示无边,diag=0),依次枚举中间点 k,更新 output[i,j] = min(output[i,j], output[i,k] + output[k,j])。
Implementation Requirements
- Use only native features (external libraries are not permitted)
- The solve function signature must remain unchanged
- 结果写入
output
Examples
见页面示例(N=4,含 +∞ 的最短路推导)。
Constraints
- 1 ≤ N ≤ 4,096;float32 或 +∞;无负环;dist[i*iN+i]=0
- dist/output 为展平的 N×N 行优先数组
- Performance: N = 2,048