title: Python: Connect disconnected graph segments with minimal cost
body: <p>Consider a graph where we have multiple segments which are disconnected between each other. I would like to find where I need to add new edges to make the graph fully connected. I'd like to keep the length of each new edge to the minimum. Bonus if the algorithm also returns the length of each edge to be added.</p>
  <hr />
  <p>Existing graph</p>
  <p><a href="https://i.stack.imgur.com/r7ddC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r7ddC.png" alt="Existing graph" /></a></p>
  <hr />
  <p>Proposed solution</p>
  <p><a href="https://i.stack.imgur.com/vc6HM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vc6HM.png" alt="Proposed solution" /></a></p>