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

PROGRAMMING:Longest path

Luz5年前 (2021-05-10)题库438
Given a positive weight directed acyclic graph and two vertices in the graph, write a program to find the longest path between the two vertices. If there are multiple longest paths between two vertices, the output dictionary order is the smallest. Suppose that the graph contains n vertices, numbered from 0 to n-1.
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 three positive integers n and E in the first line, which are the number of vertices and the number of edges of the graph, respectively, no more than 50. Next, line e represents the information of each edge, and each line has three 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. Next, 1 acts as two integers s and T, representing two vertex numbers.
###Output format:
The lexicographical order of output vertex s to vertex t is the smallest and longest path, and the vertex number in the path is separated by ">". If s and T are not connected, output "None".
###Input example:
```in
4 4
0 1 1
1 2 1
0 3 1
3 2 2
0 2
```
###Output example:
```out
0->3->2
```







answer:If there is no answer, please comment