| t | graph = {} | t | graph = {} |
| while True: | | while True: |
| s = input().strip() | | s = input().strip() |
| if ' ' in s: | | if ' ' in s: |
| a, b = s.split() | | a, b = s.split() |
| if a not in graph: | | if a not in graph: |
| graph[a] = set() | | graph[a] = set() |
| graph[a].add(b) | | graph[a].add(b) |
| if b not in graph: | | if b not in graph: |
| graph[b] = set() | | graph[b] = set() |
| graph[b].add(a) | | graph[b].add(a) |
| else: | | else: |
| start = s | | start = s |
| end = input().strip() | | end = input().strip() |
| break | | break |
| if start == end: | | if start == end: |
| print('YES') | | print('YES') |
| elif start not in graph: | | elif start not in graph: |
| print('NO') | | print('NO') |
| else: | | else: |
| visited = set() | | visited = set() |
| stack = [start] | | stack = [start] |
| visited.add(start) | | visited.add(start) |
| found = False | | found = False |
| while stack: | | while stack: |
| node = stack.pop() | | node = stack.pop() |
| if node == end: | | if node == end: |
| found = True | | found = True |
| break | | break |
| for neighbor in graph[node]: | | for neighbor in graph[node]: |
| if neighbor not in visited: | | if neighbor not in visited: |
| visited.add(neighbor) | | visited.add(neighbor) |
| stack.append(neighbor) | | stack.append(neighbor) |
| print('YES' if found else 'NO') | | print('YES' if found else 'NO') |