QOJ.ac

QOJ

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

#22558. Costruire strade

Statistics

Farmer John ha comprato nuove fattorie! Vuole strade per andare da qualsiasi a qualsiasi altra lungo una sequenza; alcune già collegate.

$N$ $(1 \le N \le 1,000)$ fattorie numerate $1..N$ in ($X_i$, $Y_i$), $(0 \le X_i \le 1,000,000; 0 \le Y_i \le 1,000,000)$. Si danno $M$ strade esistenti $(1 \le M \le 1,000)$ come coppie. Trova minima lunghezza totale aggiuntiva per collegarle tutte.

Input

Leggi input standard.

  • Riga $1$: interi $N$, $M$ separati da spazio.

  • Righe $2..N+1$: interi $X_i$, $Y_i$ separati da spazio.

  • Righe $N+2..N+M+2$: interi $i$, $j$ separati da spazio, fattorie $i$, $j$ già collegate.

Output

Scrivi output standard.

  • Riga $1$: lunghezza minima aggiuntiva, due decimali senza arrotondare. Calcola distanze con virgola mobile $64$ bit.

Esempi

Input 1

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

Output 1

4.00

Nota

Quattro fattorie in $(1,1)$, $(3,1)$, $(2,3)$, $(4,3)$; $1$, $4$ collegate.

Collega $1$, $2$ con $2.00$, poi $3$, $4$ con $2.00$, ottimo totale $4.00$.

Autore del problema: 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.