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