#P2914. [USACO08OCT] Power Failure G
[USACO08OCT] Power Failure G
题目描述
A vicious thunderstorm has destroyed some of the wires of the farm's electrical power grid! Farmer John has a map of all () of the powerpoles, which are conveniently numbered and located on integer plane coordinates ($-100000 \le x_i \le 100000, -100000 \le y_i \le 100000$).
Some () power wires connect pairs of power poles and ().
He needs to get power from pole to pole (which means that some series of wires can traverse from pole to pole , probably through some intermediate set of poles).
Given the locations of the poles and the list of remaining power wires, determine the minimum length of power wire required to restore the electrical connection so that electricity can flow from pole to pole . No wire can be longer than some real number ().
As an example, below on the left is a map of the poles and wires after the storm. For this task, . The best set of wires to add would connect poles and and also poles and .
After the storm Optimally reconnected
3 . . . 7 9 . . . . . 3 . . . 7 9 . . . . .
/
2 . . 5 6 . . . . . . 2 . . 5 6 . . . . . .
/
1 2-3-4 . 8 . . . . . 1 2-3-4 . 8 . . . . .
| |
0 1 . . . . . . . . . 0 1 . . . . . . . . .
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
The total length is then .
POINTS: 350
输入格式
Line : Two space-separated integers: and .
Line : A single real number: .
Lines : Each line contains two space-separated integers: and .
Lines : Two space-separated integers: and .
输出格式
Line 1: A single integer on a single line. If restoring connection is impossible, output -1
. Otherwise, output a single integer that is times the total minimum cost to restoreelectricity. Do not perform any rounding; truncate the resulting product.
题目大意
一场邪恶的暴风雨毁坏了农夫约翰的输电网中的一些电线!农夫约翰有一张包含了所有 ()个电能中转点的地图,中转点编号为 ,第 个点的坐标为 ()。
有 ()条电线仍然保存着没被暴风雨破坏,每条电线连接着两个电能中转点 ()。
他希望从第一个电能中转点把电导入第 个(可能通过一些中间的电能中转点,应当有一组电线连接 和 )。
给出 个电能中转点的坐标和幸存的电线,请确定最少需要架设的电线总长度,但请注意,架设过程中,对于单条电线而言,其长度不应超过()
给出一个例子,在下面,左边是一个包含 个电能中转电和 条幸存电线的地图。在这个任务中,规定 。最佳的架设方案是连接 和 ,以及 和 。
After the storm Optimally reconnected
3 . . . 7 9 . . . . . 3 . . . 7 9 . . . . .
/
2 . . 5 6 . . . . . . 2 . . 5 6 . . . . . .
/
1 2-3-4 . 8 . . . . . 1 2-3-4 . 8 . . . . .
| |
0 1 . . . . . . . . . 0 1 . . . . . . . . .
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
总长度是 。
9 3
2.0
0 0
0 1
1 1
2 1
2 2
3 2
3 3
4 1
4 3
1 2
2 3
3 4
2828
提示
Just as in the diagram above.
As above.