| t | from collections import defaultdict, deque | t | from collections import defaultdict, deque |
| graph = defaultdict(list) | | graph = defaultdict(list) |
| while True: | | while True: |
| line = input().strip() | | line = input().strip() |
| if not line: | | if not line: |
| continue | | continue |
| if ' ' not in line: | | if ' ' not in line: |
| start = line | | start = line |
| end = input().strip() | | end = input().strip() |
| break | | break |
| a, b = line.split() | | a, b = line.split() |
| graph[a].append(b) | | graph[a].append(b) |
| graph[b].append(a) | | graph[b].append(a) |
| visited = set() | | visited = set() |
| queue = deque([start]) | | queue = deque([start]) |
| visited.add(start) | | visited.add(start) |
| while queue: | | while queue: |
| current = queue.popleft() | | current = queue.popleft() |
| if current == end: | | if current == end: |
| print('YES') | | print('YES') |
| exit() | | exit() |
| for neighbor in graph[current]: | | for neighbor in graph[current]: |
| if neighbor not in visited: | | if neighbor not in visited: |
| visited.add(neighbor) | | visited.add(neighbor) |
| queue.append(neighbor) | | queue.append(neighbor) |
| print('NO') | | print('NO') |