f | from collections import defaultdict | f | from collections import defaultdict |
n | room = input() | n | a = input() |
| lab = [] | | b = [] |
| while 1: | | while 1: |
n | if room.find(' ') == -1: | n | if a.find(' ') == -1: |
| break | | break |
t | lab.append(room) | t | b.append(a) |
| room = input() | | a = input() |
| start = room | | start = a |
| finish = input() | | end = input() |
| lab2 = defaultdict(set) | | z = defaultdict(set) |
| for i in range(len(lab)): | | for i in range(len(b)): |
| (x, y) = lab[i].split(' ') | | (q, w) = b[i].split(' ') |
| lab2[x].add(y) | | z[q].add(w) |
| lab2[y].add(x) | | z[w].add(q) |
| lab3 = set() | | e = set() |
| for i in lab2[start]: | | for i in z[start]: |
| lab3.add(i) | | e.add(i) |
| for j in lab2[i]: | | for j in z[i]: |
| lab3.add(j) | | e.add(j) |
| for k in lab2[j]: | | for k in z[j]: |
| lab3.add(k) | | e.add(k) |
| for l in lab2[k]: | | for d in z[k]: |
| lab3.add(l) | | e.add(d) |
| for t in lab2[l]: | | for y in z[d]: |
| lab3.add(t) | | e.add(y) |
| for s in lab2[t]: | | for p in z[y]: |
| lab3.add(s) | | e.add(p) |
| if finish in lab3: | | if end in e: |
| print('YES') | | print('YES') |
| else: | | else: |
| print('NO') | | print('NO') |