Core idea
Kruskal sorts all edges by weight.
It adds the next smallest edge only when it connects two different components.
Union-Find is used to detect cycles efficiently.
How it works
- Sort all graph edges by ascending weight.
- Start with every vertex in its own component.
- Take the next smallest edge.
- Add it if it connects two different components; otherwise skip it.
- Stop after selecting V - 1 edges.