This is the algorithm that I implemented in the funny code for hw1: https://en.wikipedia.org/wiki/Disjoint-set_data_structure . It is called "disjoint-set data structure", or also "union find" (because it implements efficiently the two operations of finding the set given an element, and computing the union of two sets). I find the "union find" name more descriptive.
My implementation is different than the Wikipedia one, I really did write it late at night after a good dinner!
But the underlying ideas are the same, including the use of path compression.
This is a very useful general algorithm for representing sets in such a way that it's very efficient to compute the union of the sets, given elements of the sets. I use it in this example to compute the connected components of a graph, but it's quite a general algorithm.
Congratulations to those of you who submitted the correct answer!