Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Check Connectivity

(MST needs connected graph)

After running Kruskal, check if you added exactly n1n-1 edges. If you added fewer, the graph is disconnected. Some cities cannot be reached. This is a simple validation step. Count the edges in the MST. If count is less than n1n-1, return "IMPOSSIBLE".

Otherwise, return the total weight. Kruskal stops when all edges are processed. If the forest has multiple trees, you know the graph is not connected. The edge count tells you everything.