#BS0000422. Hành trình qua sa mạc (Travel in Desert)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hành trình qua sa mạc (Travel in Desert)
Travel in Desert
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A group of desert travelers plans a trip between oases. There are oases numbered from to , with departure at and destination at .
Each of the roads is bidirectional and has two attributes: the highest temperature encountered along the road, measured in degrees Celsius, and its length in kilometers. A pair of oases may be joined by several roads.
The temperature of a route is the maximum road temperature along it. Its length is the sum of the lengths of its roads.
First minimize the route temperature. Among all routes attaining that minimum, minimize the total length. Report any route satisfying both priorities.
Input
The first line contains integers , the numbers of oases and roads.
The second line contains distinct integers , the departure and destination oases.
Each of the next lines contains integers followed by decimals : the endpoints, highest temperature, and length of a road, in that order. Each decimal has exactly one digit after the decimal point.
Output
Print two lines:
- The first line lists the visited oases in travel order, beginning at and ending at , separated by spaces.
- The second line gives the route's total length followed by its maximum temperature, each with exactly one decimal digit.
Any route attaining both optimum values is accepted.
Subtasks
- Subtask 1 (20 points): ; ; , ; ; ; . Every has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from to exists.
- Subtask 2 (30 points): ; ; , ; ; ; . Every has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from to exists. All roads have the same temperature .
- Subtask 3 (50 points): ; ; , ; ; ; . Every has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from to exists.
Examples
Input
6 9
1 6
1 2 37.1 10.2
2 3 40.5 20.7
3 4 42.8 19.0
3 1 38.3 15.8
4 5 39.7 11.1
6 3 36.0 22.5
5 6 43.9 10.2
2 6 44.2 15.2
4 6 34.2 17.4
Output
1 3 6
38.3 38.3
Explanation
From oasis 1, roads to 2 and 3 have temperatures 37.1 and 38.3. Below 38.3, only oasis 2 can be reached from 1, and there is no onward route to 6. At 38.3, route 1–3–6 has maximum temperature and length km. Under this threshold, oasis 2 cannot lead onward to 6; route 1–3–6 is shortest.
Input
4 5
1 4
1 2 25.0 1.0
1 2 30.0 0.1
2 4 30.0 1.0
1 3 30.0 0.5
3 4 30.0 0.6
Output
1 2 4
1.1 30.0
Explanation
Travel from 1 to 4 must go via 2 or 3, and either choice requires temperature 30.0. At that threshold, the shorter parallel road from 1 to 2 is 0.1 km instead of 1.0 km. Continuing to 4 adds 1.0 km, totaling 1.1 km. Route 1–3–4 likewise has length km, so either is valid.