QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22558. Building Roads

Statistics

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 $N$ $(1 \le N \le 1,000)$ farms (conveniently numbered $1..N$) is represented by a position ($X_i$, $Y_i$) on the plane $(0 \le X_i \le 1,000,000; 0 \le Y_i \le 1,000,000)$. Given the preexisting $M$ roads $(1 \le M \le 1,000)$ as pairs of connected farms, help Farmer John determine the smallest length of additional roads he must build to connect all his farms.

Input

Read the input from standard input.

  • Line 1: Two space-separated integers: $N$ and $M$
  • Lines $2..N+1$: Two space-separated integers: $X_i$ and $Y_i$
  • Lines $N+2..N+M+2$: Two space-separated integers: $i$ and $j$, indicating that there is already a road connecting the farm $i$ and farm $j$.

Output

Write the output to standard output.

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

Examples

Input 1

4 1
1 1
3 1
2 3
4 3
1 4

Output 1

4.00

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

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.

Problem credits: Richard Ho, 2007

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.