## CCO '02 P5 - Connect The Campus

View as PDF

Points: 12
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Canadian Computing Competition: 2002 Stage 2, Day 2, Problem 2

Many new buildings are under construction on the campus of the University of Polkaroo. The university has hired bricklayers, electricians, plumbers, and a computer programmer. A computer programmer? Yes, you have been hired to ensure that each building is connected to every other building (directly or indirectly) through the campus network of communication cables.

We will treat each building as a point specified by an x-coordinate and a y-coordinate. Each communication cable connects exactly two buildings, following a straight line between the buildings. Information travels along a cable in both directions. Cables can freely cross each other, but they are only connected together at their endpoints (at buildings).

You have been given a campus map which shows the locations of all buildings and existing communication cables. You may not alter the existing cables. Determine where to install new communication cables so that all buildings are connected. Of course, the university wants you to minimize the amount of new cable that you use.

#### Input Specification

The input describes one test case. The first line contains the number of buildings . The buildings are labelled from to . The next lines give the and coordinates of the buildings. These coordinates are integers with absolute values at most . No two buildings occupy the same point.

Finally there is a line containing the number of existing cables followed by lines describing the existing cables. Each cable is represented by two integers: the building numbers which are directly connected by the cable. There is at most one cable directly connecting each pair of buildings.

#### Output Specification

For each new cable you plan to construct, output a line containing the numbers of the two buildings that will be joined by the cable. Also output the total length of the new cables that you plan to use, rounded to two decimal places. If there is more than one possible minimal solution you may output any such solution.

#### Sample Input

4
103 104
104 100
104 103
100 100
1
4 2

#### Sample Output

4.41
3 2
1 3