Approach
Disjoint set union
For Satisfiability of Equality Equations, the implementation maintains connected components and merges them as relationships are processed.
- Give each element a component representative.
- Merge representatives when a connection is accepted.
- Answer connectivity or component queries from the compressed representatives.
Code notes
- 42 lines of C++ from the credited upstream file 990.cpp.
- The implementation visibly relies on sequence storage.
- 2 loop blocks detected.
Complexity
Account for every find and union operation; with path compression and ranked merging, the amortized cost is nearly constant per operation.
Check the problem constraints before deciding whether this complexity will pass.