Use Union-Find or DFS to find all connected components. Each component gets a unique ID. Nodes in the same component have the same ID. After identifying components, pick one representative node from each component. You will connect these representatives. If you find components, you need exactly edges.
The problem reduces to connecting isolated nodes into a single tree. Any spanning tree of nodes works.