Spare cables connect a network
transcript
A network has separate groups. You can move a cable. How few moves connect all? Count the groups.
Union the ends of each cable. Count the groups left. Each move joins two groups. So moves are groups minus one.
Six hubs and five cables. Two hubs stand alone. That makes three groups. Two moves connect them.
Connecting n hubs needs n minus one cables. Fewer cables means no answer. Return minus one then. Check this before counting.
A chain of three hubs has two cables. Testing for n cables rejects it. Test for n minus one instead. Then the answer is zero. The test is a one-character change.
A cable inside one group is spare. It can move to join two groups. Unions that change nothing are spares. There are enough if n minus one exist. The count of groups tells the rest.
Union each cable. Count the groups. Moves are groups minus one. Full breakdown in the lecture.