Union-find
Places sorted into groups, each group led by one place. Every place points at another in its group, and following the roads up always ends at the leader, so to ask whether two places are in one group, compare their leaders; to join two groups, hang one leader under the other.
- roads followed
- 0
step 1 of 1
Examples