Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. h, k = list(map(int, input().strip().split(" ")))
  2.  
  3. ind = 0
  4. familias = {}
  5.  
  6. for x in range(h):
  7.     relation = input().split(" ")
  8.    
  9.     if x == 0:
  10.         familias[ind] = [relation[0], relation[2]]
  11.     else:
  12.         for l in range(0, ind+1):
  13.             if relation[0] in familias[l]:
  14.                 familias[l].append(relation[2])
  15.             elif relation[2] in familias[l]:
  16.                 familias[l].append(relation[0])
  17.             else:
  18.                 ind+=1
  19.                 break
  20.        
  21.         familias[ind] = [relation[0], relation[2]]
  22.  
  23. print(familias)
  24. print(ind)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement