I have to implement an algorithm where we have an existing road network (nodes connected by path ie., undirected graph). We have to connect all the cities together, and normally I would use something like Kruskal's algorithm to get a minimum spanning tree.
However, we do not care how long it takes to go between cities (can assume the edge weights are all 0 or 1 or something), rather there is a cost associated with building a road (adding an edge between 2 vertices) or destroying a road (deleting an edge between 2 vertices). This is the only cost we have to consider. Our goal is to ONLY have 1 path connecting each pair of cities. All costs are non-negative integers.
I have 3x 2d arrays (I have represented them as a matrix below, with the row and columns being the cities numbered from 0,1,2...,etc.)
Country[i][j]=1 or 0: there is an existing road between city i and j if and only if country[i][j]=1.
0 1 2
0 0 1 1
1 1 0 1
2 1 1 0
Build[i][j]: the cost for building a road between i and j
0 1 2
0 0 1 3
1 1 0 2
2 3 2 1
Destroy[i][j]: the cost for destroying a road between i and j.
0 1 2
0 0 1 3
1 1 0 2
2 3 2 1
I'm not sure how to go about this, any sort of guidance would be appreciated