Union-Find is a fast, highly efficient way to determine if two items have a common ancestor. The two operations, union and find, operate in effectively linear time. I made a single-file Rust implementation that is available for download here: https://gist.github.com/JosephCatrambone/19c3c3ef278c7a175f4acfae81f24d46