A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and the destination. If such a shortest path is not unique, you are supposed to output the one with the minimum cost, which is guaranteed to be unique.
Input Specification:
Each input file contains one test case. Each case starts with a line containing 4 positive integers N, M, S, and D, where N (≤500) is the number of cities (and hence the cities are numbered from 0 to N−1); M is the number of highways; S and D are the starting and the destination cities, respectively. Then M lines follow, each provides the information of a highway, in the format:
City1 City2 Distance Cost
where the numbers are all integers no more than 500, and are separated by a space.
Output Specif

该博客介绍了一种帮助旅行者确定从起点到目的地最短路径的程序,利用经典Dijkstra算法和深度优先搜索(DFS)。输入包含城市数量、公路数量、起点和终点,输出是最短路径的城市序列及总距离和总成本。示例展示了如何处理包含4个城市和5条公路的案例。
411

被折叠的 条评论
为什么被折叠?



