All the work done in CONNECTED. Can use depth-first-search to test connectivity. Basically, if we start at u and can reach v, they are connected. If not, not.
That gives us:
for the inner
loop. This dominates that
for sorting the edges.
Explanation: for each edge that we consider adding, we do a depth-first search over edges to see if the endpoints are already connected.