Algorithmic Heights第23题:Bellman-Ford Algorithm

Problem

Figure 1. The graph from the dataset

The task is to use Bellman-Ford algorithm to compute single-source shortest distances in a directed graph with possibly negative edge weights (but without negative cycles).

Given: A simple directed graph with integer edge weights from  to  and  vertices in the edge list format.

Return: An array  where  is the length of a shortest path from the vertex  to the vertex  (). If  is not reachable from  set  to x.

See Figure 1 for visual example from the sample dataset.

任务是使用Bellman-Ford算法来计算有向图中可能具有负边权重(但没有负循环)的有向图中的单源最短距离。

给定:一个简单的有向图,其边权重为 至  和 边列表格式的顶点。

返回:数组 哪里  是从顶点开始的最短路径的长度  到顶点  ()。如果 从以下位置无法到达  组 到x

有关示例数据集中的可视示例,请参见图1

Sample Dataset

9 13
1 2 10
3 2 1
3 4 1
4 5 3
5 6 -1
7 6 -1
8 7 1
1 8 8
7 2 -4
2 6 2
6 3 -2
9 5 -10
9 4 7

Sample Output

0 5 5 6 9 7 9 8 x
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值