Given an undirected graph, determine the minimum spanning tree.
For instance, in the example graph below, the minimum spanning
tree would have a total edge weight of 10 and consists of the following edges:
(A, C) (B, C) (C, E) (D, E) (D, F)
This problem is inspired by Challenge #152 [Hard] Minimum Spanning Tree from the DailyProgrammer subreddit.
You will be given a series of graphs specified by a distance matrix as shown below. You are to compute the minimum spanning tree and output the total edge weight of the tree and the edges in the tree.
NVERTICES -1 -1 ... -1 -1 ...
The first line specifies the number of vertices in the undirected graph, which will be between 1 and 26 (inclusive). This is followed by a distance matrix with each row separated by newlines and each column separated by spaces:
Given this following input:
6 -1 4 2 -1 -1 -1 4 -1 1 8 -1 -1 2 1 -1 -1 4 -1 -1 8 -1 -1 2 1 -1 -1 4 2 -1 7 -1 -1 -1 1 7 -1 5 -1 2 6 -1 -1 2 -1 4 1 -1 6 4 -1 -1 1 -1 1 -1 -1 1 -1 -1 1 1 -1
Your program should output the following:
10 AC BC CE DE DF 5 AB BD CE DENote that a blank line between MSTs will be required to pass the tests used for grading
We will grade your submission relative to the rubric below.
+2 Code is well formatted, commented (inc. name, assignment, and overview), with reasonable variable names +5 Uses Prim's algorithm as required +28 Test cases successfully solved (4 points each)
To faciliate testing, you were previously asked to clone the course Github repository as follows:
git clone https://github.com/semrich/cs302-fall24.git cs302
For this assignment, update this clone by using the following:
git pull
We'll discuss this in class but note that your program must be named "solution.cpp" and compilable using make. To test your solution against ours, type:
make test
To submit your solution, you must submit a single .tar archive on Canvas prior to the deadline.
Note: Although submission will be faciliated by Canvas, we will compile and test on EECS lab machines!
If you develop your solution elsewhere please make sure it works on the lab computers prior to the deadline