luogu#P1907. 设计道路

设计道路

Background

After Caesar returned from his expedition to Gaul, he praised you highly and personally came to inspect Genoa.

Under your construction, Genoa has become extremely prosperous. With increased fiscal revenue, you built a transportation system for the city. Ancient Roman transportation consists of two types of roads—Dirt Road and Rome Road. Between any two intersections, the road is of exactly one type. Carriages can run on Rome Roads, but not on Dirt Roads. Building roads is a massive project, so you could not connect the entire city with Rome Roads.

Now Caesar has arrived at the dock and wants to visit your home. Caesar has a quirk: he prefers riding to walking. Therefore, his dissatisfaction on Dirt Roads is higher than on Rome Roads.

To avoid getting dismissed by making Caesar too dissatisfied, please design a route that minimizes Caesar’s dissatisfaction.

Problem Description

You are given an undirected complete graph with n+2n+2 nodes on a 2D plane (that is, every pair of points is connected by an edge). The coordinates of node ii are Ai(xi,yi)A_i(x_i, y_i).

There are two types of edges in the undirected graph: Rome Road and Dirt Road.

Let the set of all Rome Road edges be SS, and let l(X,Y)l(X, Y) denote the length of segment XYXY. Then the weight of an edge (Ai,Aj)(A_i, A_j) is:

$$c(A_i,A_j)=\begin{cases}d_R \cdot l(A_i,A_j),&(A_i,A_j) \in S\\d_D \cdot l(A_i,A_j),&(A_i,A_j) \notin S\end{cases}$$

That is, the length of the edge times the corresponding coefficient (dRd_R for Rome Road, dDd_D for Dirt Road).

All edges incident to nodes n+1n+1 and n+2n+2 are guaranteed to be Dirt Roads.

Now, you need to find the shortest path between nodes n+1n+1 and n+2n+2.

Input Format

  • The first line contains two decimals dD,dRd_D, d_R.
  • The second line contains a positive integer nn.
  • The next nn lines: on the ii-th line, two decimals xi,yix_i, y_i.
  • Then several lines (terminated by 0 0), each containing two positive integers u,vu, v, indicating that edge (u,v)(u, v) is a Rome Road.
  • The next line contains two decimals xn+1,yn+1x_{n+1}, y_{n+1}.
  • The last line contains two decimals xn+2,yn+2x_{n+2}, y_{n+2}.

Output Format

Output the length of the shortest path between nodes n+1n+1 and n+2n+2, with 44 digits after the decimal point.

100.0 2.0
2
1.0 0.0
2.0 1.0
1 2
0 0
0.0 0.0
2.0 2.0

202.8284

Hint

Constraints (for 100%100\% of the testdata):

  • 0.1dR<dD1030.1 \le d_R < d_D \le 10^3.
  • 0p(dD),p(dR)10 \le p(d_D), p(d_R) \le 1.
  • 1n1031 \le n \le 10^3.
  • 0xi,yi1040 \le x_i, y_i \le 10^4.
  • 0p(xi),p(yi)20 \le p(x_i), p(y_i) \le 2.
  • The number of Rome Road edges does not exceed 200200.
  • 1u,vn1 \le u, v \le n (excluding the end marker).
  • uvu \ne v.

Here p(X)p(X) denotes the number of digits after the decimal point of decimal XX.

Translated by ChatGPT 5