Dimitry DungeonMap 3870
Сагура Николай, 392, сев. филиал DungeonMap 3975
t1from collections import defaultdict, dequet1from collections import defaultdict, deque
2graph = defaultdict(list)2graph = defaultdict(list)
3while True:3while True:
4    line = input().strip()4    line = input().strip()
5    if not line:5    if not line:
6        continue6        continue
7    if ' ' not in line:7    if ' ' not in line:
8        start = line8        start = line
9        end = input().strip()9        end = input().strip()
10        break10        break
11    a, b = line.split()11    a, b = line.split()
12    graph[a].append(b)12    graph[a].append(b)
13    graph[b].append(a)13    graph[b].append(a)
14visited = set()14visited = set()
15queue = deque([start])15queue = deque([start])
16visited.add(start)16visited.add(start)
17while queue:17while queue:
18    current = queue.popleft()18    current = queue.popleft()
19    if current == end:19    if current == end:
20        print('YES')20        print('YES')
21        exit()21        exit()
22    for neighbor in graph[current]:22    for neighbor in graph[current]:
23        if neighbor not in visited:23        if neighbor not in visited:
24            visited.add(neighbor)24            visited.add(neighbor)
25            queue.append(neighbor)25            queue.append(neighbor)
26print('NO')26print('NO')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op