Floyd Warshall算法

本文介绍了Floyd Warshall算法,这是一个解决加权有向图中所有对最短路径问题的算法,适用于包括负权重边的情况。通过邻接矩阵表示图,并逐步检查是否存在能缩短路径的中间节点来更新最短距离。提供了C++实现示例,并展示了算法在求解图的最短路径上的应用。
摘要由CSDN通过智能技术生成

Description:

描述:

This is a very popular interview problem to find all pair shortest paths in any graph. This problem has been featured in interview rounds of Samsung.

这是一个非常流行的面试问题,用于在任何图中找到所有对最短路径。 该问题已在三星的采访回合中提到。

Problem statement:

问题陈述:

Given a weighted directed graph, the problem is to find the shortest distances between every pair of vertices. The Graph is represented by an adjacency matrix, and any cell arr[i][j] denotes the weight of the edge (path cost) from node i to node j (if it exists) else INF.

给定一个加权有向图,问题在于找到每对顶点之间的最短距离。 该图由邻接矩阵表示,任何单元格arr [i] [j]表示从节点i到节点j (如果存在)或其他INF的边的权重(路径成本)。

Input: N=5

输入: N = 5

Adjacency matrix:

邻接矩阵:

floyd warshall algorithm (1)

Example:

例:

So the graph for the above input is,

因此,上述输入的图形为

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值