PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000422. Hành trình qua sa mạc (Travel in Desert)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 NN oases numbered from 11 to NN, with departure at SS and destination at TT.

Each of the EE roads is bidirectional and has two attributes: the highest temperature RR encountered along the road, measured in degrees Celsius, and its length DD 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 N,EN,E, the numbers of oases and roads.

The second line contains distinct integers S,TS,T, the departure and destination oases.

Each of the next EE lines contains integers X,YX,Y followed by decimals R,DR,D: 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 SS and ending at TT, 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): 2≤N≤82\le N\le 8; 1≤E≤251\le E\le 25; 1≤S,T≤N1\le S,T\le N, S≠TS\ne T; 1≤X,Y≤N1\le X,Y\le N; 20≤R≤5020\le R\le 50; 0<D≤400<D\le 40. Every R,DR,D has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from SS to TT exists.
  • Subtask 2 (30 points): 2≤N≤1002\le N\le 100; 1≤E≤100001\le E\le 10000; 1≤S,T≤N1\le S,T\le N, S≠TS\ne T; 1≤X,Y≤N1\le X,Y\le N; 20≤R≤5020\le R\le 50; 0<D≤400<D\le 40. Every R,DR,D has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from SS to TT exists. All roads have the same temperature RR.
  • Subtask 3 (50 points): 2≤N≤1002\le N\le 100; 1≤E≤100001\le E\le 10000; 1≤S,T≤N1\le S,T\le N, S≠TS\ne T; 1≤X,Y≤N1\le X,Y\le N; 20≤R≤5020\le R\le 50; 0<D≤400<D\le 40. Every R,DR,D has exactly one decimal digit; roads are bidirectional, parallel roads are allowed, and a route from SS to TT 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 max⁡(38.3,36.0)=38.3\max(38.3,36.0)=38.3 and length 15.8+22.5=38.315.8+22.5=38.3 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 0.5+0.6=1.10.5+0.6=1.1 km, so either is valid.