--- id: dsu title: "Disjoint Set Union" author: Benjamin Qi, Michael Cao prerequisites: - Silver - Depth First Search description: The Disjoint Set Union (DSU) data structure allows you to add edges to an initially empty graph and test whether two vertices of the graph are connected. --- ## Tutorial - CPH 15.2 - [PAPS 11.1](https://www.csc.kth.se/~jsannemo/slask/main.pdf) - Chapter 10.6 of "An Introduction to the US Computing Olympiad" - [CSAcademy Disjoint-Set](https://csacademy.com/lesson/disjoint_data_sets) - [Topcoder Union Find](https://www.topcoder.com/community/data-science/data-science-tutorials/disjoint-set-data-structures/) - [CPC.3](https://github.com/SuprDewd/T-414-AFLV/tree/master/03_data_structures) - DSU Complexity Proofs (optional of course) - [log\*n](https://en.wikipedia.org/wiki/Proof_of_O(log*n)\_time_complexity\_of_union%E2%80%93find) - [a(m,n)](https://dl.acm.org/doi/pdf/10.1145/321879.321884) with rollback: https://codeforces.com/contest/1140/problem/F ## Problems - [Mootube](http://www.usaco.org/index.php?page=viewproblem2&cpid=789) - same as [CSES Road Construction](https://cses.fi/problemset/task/1676) - [Closing the Farm](http://www.usaco.org/index.php?page=viewproblem2&cpid=646) - [CSES Network Breakdown](https://cses.fi/problemset/task/1677) - [Favorite Colors](http://www.usaco.org/index.php?page=viewproblem2&cpid=1042) - fairly tricky