Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_path(graph, start, end, path=[]):
- path = path + [start]
- if start == end:
- return path
- if not graph.__contains__(start):
- return None
- for node in graph[start]:
- if node not in path:
- newpath = find_path(graph, node, end, path)
- if newpath: return newpath
- return None
- n=int(input())
- graph={}
- for x in range(n):
- current_task=[i for i in input().split()]
- key=current_task[0]
- del current_task[0]
- graph[key]=[]
- for task in current_task:
- if task==':': continue
- else:
- graph[key].append(task)
- n=int(input())
- find_way=[]
- for x in range(n):
- find_way.append([i for i in input().split()])
- for points in find_way:
- if find_path(graph, points[1], points[0])==None: print ('No')
- else: print('Yes')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement