#P2632. Explorer

Explorer

Description

Given two straight lines with n,mn, m points on them respectively, find the minimum spanning tree formed by these n+mn + m points.

Input Format

The input consists of 55 lines.

  • The first line contains nn and mm.
  • The second line contains four integers xa,ya,xb,ybx_a,y_a,x_b,y_b.
  • The third line contains four integers xc,yc,xd,ydx_c,y_c,x_d,y_d.
  • The fourth line contains nn real numbers, representing nn points on the first line. For a point, a real number tt indicates that the coordinates of the point are (txa+(1t)xb,tya+(1t)yb)(t x_a + (1 - t) x_b, t y_a + (1 - t) y_b).
  • The fifth line contains mm real numbers, representing mm points on the second line, in the same manner as above.

Output Format

Output a single real number on one line: the length of the minimum spanning tree, rounded to three decimal places.

4 4 
0 0 10 10 
0 10 10 0 
0.1 0.3 0.6 0.8 
0.1 0.3 0.6 0.8
19.638

Hint

Constraints: 1n,m1000001 \le n,m \le 100000, and the absolute values of xa,ya,xb,yb,xc,yc,xd,ydx_a,y_a,x_b,y_b,x_c,y_c,x_d,y_d are all less than or equal to 10510^5. 0t10 \le t \le 1.

2024/2/8: Added one hack testdata.

Translated by ChatGPT 5