Instead of creating a new set for , take ownership of the largest child's set. This avoids copying large sets. In C++, you can swap sets using std::swap or move them with std::move. In Python, reassign references.
After taking the big set, merge smaller sets into it element by element. Then add 's value. The big set is now 's set. This reuse is what makes the technique fast in practice.