Let me walk through the solution step by step using a sample input. You will see how edges are sorted, how Union-Find detects cycles, and how the MST is built. I'll trace through each edge decision: add or skip. You will see the component merges and the running total of the MST weight.
Watch how the edge count grows from to . This walkthrough shows you the algorithm in action. Follow along to see how all the pieces fit together.