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

PROGRAMMING:Shortest path Dijkstra

Luz5年前 (2021-05-10)题库361
The roads of the city extend in all directions. We often need to find the path from one place to another. Of course, we hope to get there as soon as possible. Now get the time to go to each place, now please write a program to calculate the shortest time from a specific place to all cities.
###Input format:
The first line of input gives the number of cities n (1 ≤ n ≤ 10) and the number of roads m and 1 (for digraph) or 0 (for undirected graph);
The next M line corresponds to the travel time between each city. Each line gives three positive integers, which are the number of the two cities (from 1 to n) and the travel time between the two cities. The last line gives a number, indicating the starting point from this number.
###Output format:
Output the distance from a specific place to all cities (in the order of 1-N). If there is no way, please output no path. Each city accounts for one line.
###Input example:
```in
4 4 1
1 2 2
1 4 8
3 2 16
3 4 10
one
```
###Output example:
```out
1->1:0
1->2:2
1->3:no path
1->4:8
```







answer:If there is no answer, please comment