Advertisement
Guest User

Untitled

a guest
May 25th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import sys
  2.  
  3.  
  4. def vhoj(parent, child):
  5.     if child == ('' or []):
  6.         return tempor
  7.  
  8.     if parent in ke.keys() and parent != child:
  9.  
  10.         for cur_child in child:
  11.             tempor.update([cur_child])
  12.             child = ''.join(map(str, cur_child))
  13.             if child == '':
  14.                 return tempor
  15.             vhoj(child, ke[child])
  16.             #vhoj(child, ''.join(map(str, ke[child])))
  17.     return tempor
  18.  
  19.  
  20. herit = {}
  21.  
  22. file = open("C:\\Users\\Andrey\\PycharmProjects\\CursePython\\St.txt", 'r')
  23. sys.stdin = file
  24.  
  25. clases = [input() for _ in range(int(input()))]
  26. herit_class = [input() for _ in range(int(input()))]
  27.  
  28. ke = {}
  29.  
  30. for elm in clases:
  31.     #if elm[0] not in ke:
  32.     nam = elm.find(':')
  33.     if nam == -1:
  34.         ke[elm] = []
  35.         continue
  36.     cur = {elm[0: nam -1]: elm[nam+1:].split()}
  37.     ke.update(cur)
  38. #print(ke)
  39.  
  40. #print(clases, herit_class)
  41.  
  42. for couple in ke.keys():
  43.     tempor = set()
  44.     herit[couple] = vhoj(couple, ke[couple])
  45.  
  46.     #print(herit)
  47.  
  48. for couple in herit_class:
  49.     couple = couple.split()
  50.     if couple[0] in herit[couple[1]] or couple[0] == couple[1]:
  51.         print("Yes")
  52.     else:
  53.         print('No')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement