I struggled a lot with the direction, but realised way too much later
that the mappings are bidirectional.
Part 2 was exceptionally hard, but I realised early that the order did
not matter and that a simple boolean lock was all that was needed. The
challenge was to know when to watch for duplicates.
The seen was initially a set, but since new sets must be sent instead of
references, a list is used instead to be able to use the seen + [] hack.