You are to write a program that takes a single additional command line argument (for a total of 2 arguments, including the command name) that gives the name of an input file:
The file will be a sequence of connections between computers and their associated costs. Each connection will be on its own line and appear as follows:
< name1 > < name2 > < cost >
Where
So, one example input file might look like:
Allentown Bethlehem 12
Allentown Indianapolis 25
Bethlehem Chicago 10
Bethlehem Hartford 40
Bethlehem Indianapolis 8
Chicago Detroit 18
Chicago GreenBay 55
Detroit Edwardsville 44
Edwardsville Fargo 60
Edwardsville GreenBay 38
GreenBay Hartford 35
Hartford Indianapolis 35
Note that all communication lines are undirected, so the connection from Bethlehem to Hartford at a cost of 40 means that Hartford can also communicate with Bethlehem using the same line.
The program should then print out the total cost of a minimum cost network that would allow all computers to be connected, but not necessarily with direct connections between all computers. For the example above, the resulting cost would be 216.
Your program must run in better than m2 time, where is the number of connections specified in the input file !!!!
Suppose you have the above example stored an an input file called simple.txt. Then you could run the program as (assuming your executable name is p6sol) :
./p6sol simple.txt
And the resulting output would be:
216