2067. Building Roads

单点时限: 2.0 sec

内存限制: 256 MB

Farmer John had just acquired several new farms! He wants to connect the farms with roads so that he can travel from any farm to any other farm via a sequence of roads; roads already connect some of the farms.

Each of the () farms (conveniently numbered ..) is represented by a position on the plane (, ). Given the preexisting roads () as pairs of connected farms, help Farmer John determine the smallest length of additional roads he must build to connect all his farms.

输入格式

  • Line : Two space-separated integers: and
  • Lines ..: Two space-separated integers: and
  • Lines ..: Two space-separated integers: and , indicating that there is already a road connecting the farm and farm .

输出格式

  • Line : Smallest length of additional roads required to connect allfarms, printed without rounding to two decimal places. Be sure to calculate distances as 64-bit floating point numbers.

样例

Input
4 1
1 1
3 1
2 3
4 3
1 4
Output
4.00

提示

INPUT DETAILS:

Four farms at locations (1,1), (3,1), (2,3), and (4,3). Farms 1 and 4 are connected by a road.

OUTPUT DETAILS:

Connect farms 1 and 2 with a road that is 2.00 units long, then connect farms 3 and 4 with a road that is 2.00 units long. This is the best we can do, and gives us a total of 4.00 unit lengths.

254 人解决,315 人已尝试。

621 份提交通过,共有 1866 份提交。

6.1 EMB 奖励。

创建: 11 年,2 月前.

修改: 1 年,4 月前.

最后提交: 4 天,4 小时前.

来源: USACO

题目标签