Does this "reference" problem have a name?
This is disjoint-set data structure. 

Here is the summary at Wikipedia. I put the statement about time-complexity in bold font to emphasize its efficiency.


  In computer science, a disjoint-set data structure (also called a union–find data structure or merge–find set) is a data structure that tracks a set of elements partitioned into a number of disjoint (non-overlapping) subsets. It provides near-constant-time operations (bounded by the inverse Ackermann function) to add new sets, to merge existing sets, and to determine whether elements are in the same set. In addition to many other uses (see the Applications section), disjoint-sets play a key role in Kruskal's algorithm for finding the minimum spanning tree of a graph.


There are many tutorials for this data structures on the web, such as the one at TopCoder and the one at GeeksforGeeks.