Pick one node from each component as a representative. For example, use the smallest-numbered node in each component. Connect the representatives in a chain: , ,., . This uses exactly edges. Any chain works.
The problem does not ask for minimum weight, minimum number of edges. A linear chain is the simplest solution that always works. You can find components with DFS, BFS, or DSU before connecting them.