31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Below is sample of map of the Kingdom of42Fancy. Towns are marked with ringed numbers.Number written at the appropriate segment indicatesthe length of the road. The cleaned roads1087 20are marked with thicker lines. The total length35of the cleaned roads is the least.71Traffic is two-way in all roads and each roadconnects two different towns. Traffic net in thePicture 178.1Kingdom of Fancy is such that it is possible todrive from any town to any other one (of course, when roads are not snowbound) –directly or through intermediate towns.Task. Write an algorithm to find such a set of roads that after cleaning them it would bepossible to drive from any one town to any another town. The total length of the roads tobe cleaned should be the least. If several solutions are possible, find any one of them.Input. The first line of the input file contains the number of towns n (2 ≤ n ≤ 170).Towns are numbered from 1 to n.Further there are n lines and each of them contains n positive integers separatedwith space characters: in the i’th line there are written lengths of roads from town i toall other towns, herein j number in line i means the number of road that connectstowns i and j. If there is no direct road between towns i and j, then the length of theroad is marked with zero.None of the input data exceeds maxint. General length of all roads does not exceedmaxlongint.Note that number j in the line i always coincides with number i in line j because allthe roads are two–way. Besides, number i is always equal to 0 in line i, because thereare no roads – loops.Output. The first line of the output file should contain the total length of the roadsto be cleaned.In the remaining lines indicate the roads that will be cleaned – one road per line.Road is indicated by the numbers of towns it connects.The order of presenting roads is not important. It is possible to write numbersdescribing town in any order when indicating particular road.Example (coincides with the map presented in this task)Input Output Comments50 20 0 0 020 0 7 15 00 7 0 8 70 15 8 0 100 0 7 10 0422 13 25 34 315In this case the problem has the onlysolution; it can be presented notnecessarily as in this example. The firstline must remain the same, and the otherlines can be swapped. Numbers in thoselines can also be swapped.15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!