Skip to content

Instantly share code, notes, and snippets.

@Dmitry-Ronzhin
Created August 7, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dmitry-Ronzhin/3bb07aecd65e41862fd7e4bf2747530f to your computer and use it in GitHub Desktop.
Save Dmitry-Ronzhin/3bb07aecd65e41862fd7e4bf2747530f to your computer and use it in GitHub Desktop.
with open('input_pairs.txt') as f:
ids = {}
lines = f.readlines()
for line in lines:
p,q = [int(x) for x in line.split(' ')]
if p not in ids:
ids[p] = p
if q not in ids:
ids[q] = q
if ids[p] == ids[q]:
continue
t = ids[p]
for key in ids:
if ids[key] == t:
ids[key] = ids[q]
print(p,q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment