Algorithmic Heights第18题:Dijkstra‘s Algorithm

Problem

Figure 1. The graph from the dataset

图1 数据集中的图形

The task is to use Dijkstra's algorithm to compute single-source shortest distances in a directed graph with positive edge weights.

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

Return: An array  where  is the length of a shortest path from the verte

任务是使用Dijkstra算法在具有正边权重的有向图中计算单源最短距离。

下式给出:简单向图具有正边缘权重从 至  和 边列表格式的顶点。

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

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

 

Sample Dataset

6 10
3 4 4
1 2 4
1 3 2
2 3 3
6 3 2
3 5 5
5 4 1
3 2 1
2 4 2
2 5 3

Sample Output

0 3 2 5 6 -1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值