编程介的小学生 2017-02-16 10:18 采纳率: 20.3%
浏览 786
已采纳

Jill's Tour Paths

Every year, Jill takes a bicycle tour between two villages. There are different routes she can take between these villages, but she does have an upper limit on the distance that she wants to travel. Given a map of the region indicating the cities and the roads between them (and their distances), Jill would like to have a list of the various routes between the selected cities that will meet her distance requirements. Your task is to write a program that will produce a list of these routes, in increasing order of distance.

We make the following assumptions.
•At most one road connects any pair of villages, and this road is two-way and has a non-zero positive distance.
•There are no roads that lead directly from a village back to the same village.
•Jill is only concerned about a one-way trip. That is, she is not concerned about returning to the village from which she starts her tour.
•Jill will not visit any village more than once during the tour.
•The farthest Jill will ever travel is 9999 units.

Input

The input will contain several possible cases, each including a route map, identification of the start and destination villages, and the maximum distance Jill is willing to travel.

Each case appears in the input as a set of integers separated by blanks and/or ends of lines. The order and interpretation of these integers in each case is as follows:
•NV - the number of villages in the route map. This number will be no larger than 20.
•NR - the number of roads that appear in the route map. Each road connects a distinct pair of villages.
•NR triples, one for each road, containing C1, C2, and DIST - C1 and C2 identify two villages connected by a road, and DIST gives the distance between these villages on that road.
•SV, DV - the numbers associated with the start and destination villages; the villages are numbered 1 to NV.
•MAXDIST - the maximum distance Jill is willing to travel (one way).

The data for the last case will be followed by a single integer with the value -1.

Output

For each case, display the case number (1, 2, ...) on the first line of output. Then, each on a separate additional line, list the routes that Jill might take preceded by the length of the route. Order the routes first by length, from shortest to longest. Within routes having the same length, order them in increasing lexicographic order. The sample input and output provide suitable examples, and the formatting shown there should be followed closely (each village number should be separated by a single space).

Separate the output for consecutive cases by a single blank line.

Sample Input

4 5
1 2 2
1 3 3
1 4 1
2 3 2
3 4 4
1 3
4

4 5
1 2 2
1 3 3
1 4 1
2 3 2
3 4 4
1 4
10

5 7
1 2 2
1 4 5
2 3 1
2 4 2
2 5 3
3 4 3
3 5 2
1 3
8

-1

Sample Output

Case 1:
3: 1 3
4: 1 2 3

Case 2:
1: 1 4
7: 1 3 4
8: 1 2 3 4

Case 3:
3: 1 2 3
7: 1 2 4 3
7: 1 2 5 3
8: 1 4 2 3
8: 1 4 3

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-17 15:19
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算