cho.sh
Notes
Loading...

Communicating with the Space Gods

Time limit

2s

Memory limit

128 MB

Problem

Hwang Seon-ja is a channeler who can communicate with space gods. Because there are many space gods, directly communicating with every one of them is exhausting.

Fortunately, every space god does not need a direct connection to Seon-ja. If a space god is already connected to Seon-ja, or can reach Seon-ja through passages connected to other space gods, communication is possible.

Communication happens through mental passages between Seon-ja and a space god, or between two space gods. Longer passages require more effort, so the total length of newly built passages should be as small as possible.

Seon-ja and the space gods live on a 2D coordinate plane. The length of a passage between two beings is the Euclidean distance between their coordinates.

Some passages are already connected. Add passages so that every being belongs to one connected network, while minimizing the total length of the newly added passages.

Input

The first line contains the number of space gods NNN (1≤N≤1 0001 \le N \le 1\,0001≤N≤1000) and the number of already connected passages MMM (1≤M≤1 0001 \le M \le 1\,0001≤M≤1000).

Each of the next NNN lines contains the coordinates XXX, YYY (0≤X,Y≤1 000 0000 \le X, Y \le 1\,000\,0000≤X,Y≤1000000) of one being, including Seon-ja. The beings are numbered from 1 to NNN in input order, and all coordinates are integers.

Each of the following MMM lines contains two numbers that are already connected by a passage.

Output

Print the minimum total length of the passages that must be newly built, rounded to two digits after the decimal point.

Hint

Suppose the coordinates are (1,1)(1, 1)(1,1), (3,1)(3, 1)(3,1), (2,3)(2, 3)(2,3), and (4,3)(4, 3)(4,3), and beings 1 and 4 are already connected. If you additionally connect 1 with 2 and 3 with 4, every being can reach every other being and the total length of the newly built passages is minimized.