#P4579. [FJOI2018] 邮递员问题

[FJOI2018] 邮递员问题

Description

Since 2010\text{2010}, the online shopping market has developed rapidly, and courier companies have become a key part of making transactions successful. Xiao Guo is an SF Express courier. His salary mainly includes a basic wage, delivery commission, pickup commission, other benefits and subsidies, etc. For each completed parcel order, Xiao Guo can usually get a commission of 10%10\% of the shipping fee. Therefore, the more orders he completes and the faster he completes them, the higher his income will be.

Xiao Guo is responsible for all courier services on 22 parallel streets in the city. On these 22 parallel streets, there are 22 courier stations. Each delivery route starts from one station, and after delivering all parcels, ends at the other station. To finish the task efficiently, Xiao Guo wants to use the shortest route to complete all deliveries.

That is, given the distance between the 22 parallel streets, the positions of the 22 stations, and the positions of all delivery points, Xiao Guo needs to compute the shortest route that starts from one station, delivers all parcels, and finally returns to the other station.

The street distance means the vertical distance between the 22 parallel streets. If we set the xx axis parallel to the streets, and the leftmost positions on both streets have x=0x=0, then any position on the 22 streets can be represented by the straight-line distance from the leftmost end of the street to that position, i.e., the xx coordinate value of that position.

For example, suppose the street distance between streets A and B is 22. The two stations S1S_1 and S2S_2 are located at street A, x=1x=1, and street B, x=3x=3, respectively. There are also 22 delivery points T1T_1 and T2T_2 located at street A, x=3x=3, and street B, x=1x=1, respectively, as shown in the figure. Xiao Guo’s task is to start from station S1S_1, deliver the parcels at T1T_1 and T2T_2, and then return to the other station S2S_2.

Programming task: given the street distance of the 22 parallel streets, the positions of the 22 stations, and the positions of all delivery points, compute the shortest route that starts from one station, delivers all parcels, and ends at the other station.

Input Format

The first line contains two positive integers n,mn,m, 1n,m100001 \le n,m \le 10000, representing the number of positions on the two parallel streets A and B (including delivery points and station positions). The positions are numbered as A: 1,2,,n1,2,\ldots,n; B: 1,2,,m1,2,\ldots,m.

The second line contains four positive integers a,b,c,da,b,c,d, indicating that the two station positions are (a,b)(a,b) and (c,d)(c,d). a=0a=0 or c=0c=0 means the corresponding station is on street AA, and a=1a=1 or c=1c=1 means the corresponding station is on street BB. bb and dd represent the position indices of the stations on the corresponding streets. For example, (a,b)=(0,3)(a,b)=(0,3) means the first station is on street AA, and its position is the 33-rd among the given nn positions of street AA.

The third line contains one real number hh, representing the street distance between the 22 parallel streets (1h10)(1 \le h \le 10).

The fourth line contains nn real numbers, representing the xx coordinates of the nn positions on street AA (1x<20000)(1 \le x < 20000).

The fifth line contains mm real numbers, representing the xx coordinates of the mm positions on street BB (1x<20000)(1 \le x < 20000).

Output Format

Output the computed shortest route length, rounded to 22 decimal places.

2 2
0 1 1 2
2
1 3
1 3
6.83

Hint

For 10%10\% of the testdata, n,m8n,m\le 8.

For 30%30\% of the testdata, n,m100n,m\le 100.

For 50%50\% of the testdata, n,m1000n,m\le 1000.

For 100%100\% of the testdata, n,m10000n,m\le 10000.

Translated by ChatGPT 5