Skip to content

Union-find

storing

Level 3 of 3

Also called Disjoint-set forest and Merge-find set.

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

Two different places from 1 to 9, with a dash between and no spaces, join them. Up to 12 joins, separated by commas or spaces, for example 1-2, 3-4, 2-3.