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

PROGRAMMING:Least point lexicographic shortest path

Luz5年前 (2021-05-10)题库455
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, the shortest path from 0 to 4 passing through the least vertices in Figure 1 (a) is 0 - 3 - 4. If there are multiple shortest paths and the number of vertices they pass through is equal, the output lexicographic order is the smallest. For example, in Figure 1 (b), the shortest path from 0 to 5 satisfying the condition is 0 - 2 - 5.
![ g.jpg](~/cab6dc09-fd1d-4802-9301-31c3136e05eb.jpg)
Note: dictionary order is the order of objects in the dictionary. For two digit sequences, the comparison starts from the first digit. When the digits in a certain position are different, the sequence with smaller digits in that position has smaller dictionary order, for example, 1239 is smaller than 1245, 1289 is smaller than 12103.
###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
6 7
0 1 1
1 4 2
4 5 3
0 3 4
3 5 2
0 2 5
2 5 1
```
###Output example:
```out
0->1
0->2
0->3
0->1->4
0->2->5
```







answer:If there is no answer, please comment