Approach
Disjoint set union
For ABC424 C — New Skill Acquired, 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
- 47 lines of Python from the credited upstream file abc424_c.py.
- The implementation visibly relies on hash lookup, ordered lookup, work queue.
- No explicit 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.