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 nodes on a 2D plane (that is, every pair of points is connected by an edge). The coordinates of node are .
There are two types of edges in the undirected graph: Rome Road and Dirt Road.
Let the set of all Rome Road edges be , and let denote the length of segment . Then the weight of an edge 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 ( for Rome Road, for Dirt Road).
All edges incident to nodes and are guaranteed to be Dirt Roads.
Now, you need to find the shortest path between nodes and .
Input Format
- The first line contains two decimals .
- The second line contains a positive integer .
- The next lines: on the -th line, two decimals .
- Then several lines (terminated by
0 0), each containing two positive integers , indicating that edge is a Rome Road. - The next line contains two decimals .
- The last line contains two decimals .
Output Format
Output the length of the shortest path between nodes and , with 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 of the testdata):
- .
- .
- .
- .
- .
- The number of Rome Road edges does not exceed .
- (excluding the end marker).
- .
Here denotes the number of digits after the decimal point of decimal .
Translated by ChatGPT 5