-->
当前位置:首页 > 题库

PROGRAMMING:Minimum vertex shortest path

Luz5年前 (2021-05-10)题库448
Given a positive weighted digraph, the graph contains n vertices, numbered from 0 to n-1. Taking vertex 0 as the source point, the shortest path from vertex 0 to each vertex is calculated by programming. If there are multiple shortest paths from vertex 0 to a vertex, the path passing through the least vertices will be output. For example, in Figure 1, there are two shortest paths from 0 to 4, 0 → 1 → 2 → 4 and 0 → 3 → 4. The sum of weights is 6, but the number of vertices passing through 0 → 3 → 4 is the least, so it is the required path. The input data ensures that there is at most one path satisfying the above conditions for each vertex.
![ GRAPH.png](~/4533d6c3-2f9a-470c-8877-20a698c0f63c.png)
###Input format:
Enter two positive integers n and E in the first line to represent the number of vertices and edges of the graph, where n does not exceed 15000 and E does not exceed 1000. Next, line e represents the information of each edge, and each line contains three non negative integers a, B, and C, where a and B represent the endpoint number of the edge, and C represents the weight. The sides are not arranged in end numbered order.
###Output format:
The output is a series of numbers separated by ">", each line is the shortest path from the source point 0 to a vertex, if there is no shortest path from the source point to a vertex, the path will not be output. The shortest path from source point to source point does not need to be output.
###Input example:
```in
5 5
0 1 1
0 3 4
1 2 2
2 4 3
3 4 2
```
###Output example:
```out
0->1
0->1->2
0->3
0->3->4
```







answer:If there is no answer, please comment