Try removing each edge and check if the remaining graph is a tree (connected with no cycles).
For each of edges, checking connectivity takes . Total: .
Can you detect the cycle-forming edge as you process edges?
The trap
Try removing each edge and check if the remaining graph is a tree (connected with no cycles).
For each of edges, checking connectivity takes . Total: .
Can you detect the cycle-forming edge as you process edges?