#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 NN (2N10002\le N \le 1000) of the powerpoles, which are conveniently numbered 1N1\ldots N and located on integer plane coordinates (xi,yi)(x_i,y_i) ($-100000 \le x_i \le 100000, -100000 \le y_i \le 100000$).

Some WW (1W100001 \le W \le 10000) power wires connect pairs of power poles PiP_i and PjP_j (1PiN,1PjN1 \le Pi \le N, 1 \le Pj \le N).

He needs to get power from pole 11 to pole NN (which means that some series of wires can traverse from pole 11 to pole NN, probably through some intermediate set of poles).

Given the locations of the NN 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 11 to pole NN. No wire can be longer than some real number MM (0.0<M200000.00.0 < M \le 200000.0).

As an example, below on the left is a map of the 99 poles and 33 wires after the storm. For this task, M=2.0M = 2.0. The best set of wires to add would connect poles 44 and 66 and also poles 66 and 99.

   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 1.414213562+1.414213562=2.8284271241.414213562 + 1.414213562 = 2.828427124.

POINTS: 350

输入格式

Line 11: Two space-separated integers: NN and WW.

Line 22: A single real number: MM.

Lines 3N+23\ldots N+2: Each line contains two space-separated integers: xix_i and yiy_i.

Lines N+3N+2+WN+3\ldots N+2+W: Two space-separated integers: PiP_i and PjP_j.

输出格式

Line 1: A single integer on a single line. If restoring connection is impossible, output -1. Otherwise, output a single integer that is 10001000 times the total minimum cost to restoreelectricity. Do not perform any rounding; truncate the resulting product.

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.