Economic crisis affected many countries. X Country is one of these countries. The government wants to make some savings. In the cities of X Country, street lights are turned on all night. The cost of a turned on street light is 1 xDollars. The government decides to turn off some lights but they still want to establish a safe, peaceful environment. Therefore, the government wants to supply at least one lighted road from a crossroad to another crossroad even if the road is not the shortest path between the crossroads. Roads consist of one or more streets. Crossroads connect the streets to each other. Streets are dual carriageway; cars both go and come back from a street.
You are going to be given a city plan of some cities in X Country which holds crossroads and number of lights on the streets. By supplying the restriction of the government maximum how many xDollars can be saved for a day?
City plan documentation format:
A city consists of m crossroads and n streets. You are going to be given an input file called “cityplan.txt”. The first line of the input file holds the numbers of m and n respectively. The following lines hold mi. and mj. crossroads and the number of the lights on the street between these crossroads (i != j).
As an output, print the lighted streets by representing them with crossroads that they connect. Give the total savings in xDollars, and calculate and print the percentage of gain. In the last line, give the running time of the algorithm in milliseconds. You can run the algorithm for 1000 times in order to obtain a statistically significant value.
Well, even if this is a MST of this particular city graph, my guess is that
you'll have to write something that works for any (connected) city graph.
I'm sure you can find good C++ implementations of the three algorithms mentioned in wikipedia (Boruvka's, Prim's, Kruskal's) if you google using the right keywords, but I believe it would be better for you to pick one of them, try to understand how it works by reading the pseudo code and then try to implement it yourself.