Advertisement
Danila_lipatov

checker_week_2_stepik

Apr 23rd, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # put your python code here
  2. n = int(input())
  3. classes = {}
  4. for i in range(n):
  5.     line = input()
  6.     parts = line.split(" : ")
  7.     cls = parts[0]
  8.     if len(parts) == 1:
  9.         classes[cls] = []
  10.     else:
  11.         classes[cls] = parts[1].split(" ")
  12.  
  13.  
  14. def check(src, dest):
  15.     if src == dest:
  16.         return True
  17.     return any([check(child, dest) for child in classes[src]])
  18.  
  19.  
  20. m = int(input())
  21. used = []
  22.  
  23. for i in range(m):
  24.     cls = input()
  25.     if any([check(cls, used_one) for used_one in used]):
  26.         print(cls)
  27.     used.append(cls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement