n | def linear(name, list_): | n | def linear(name, lst): |
| res = [name] | | res = [name] |
n | while len(list_) != 0: | n | while len(lst) != 0: |
| l = len(list_) | | l = len(lst) |
| i = 0 | | i = 0 |
| flag = True | | flag = True |
n | cl = list_[i][0] | n | cl = lst[i][0] |
| chosen = [cl] | | chosen = [cl] |
| k = 0 | | k = 0 |
| while k < l: | | while k < l: |
n | if k != i and cl != list_[k][0] and (cl in list_[k]): | n | if k != i and cl != lst[k][0] and (cl in lst[k]): |
| i = k | | i = k |
n | cl = list_[i][0] | n | cl = lst[i][0] |
| if cl in chosen: | | if cl in chosen: |
| return ([], False) | | return ([], False) |
| chosen.append(cl) | | chosen.append(cl) |
| k = int(not i) | | k = int(not i) |
| else: | | else: |
| k += 1 | | k += 1 |
| res.append(cl) | | res.append(cl) |
| for i in range(l - 1, -1, -1): | | for i in range(l - 1, -1, -1): |
n | if list_[i][0] == cl: | n | if lst[i][0] == cl: |
| if len(list_[i]) == 1: | | if len(lst[i]) == 1: |
| del list_[i] | | del lst[i] |
| else: | | else: |
n | del list_[i][0] | n | del lst[i][0] |
| return (res, True) | | return (res, True) |
| ans = True | | ans = True |
| lin = dict() | | lin = dict() |
| names = dict() | | names = dict() |
n | while ans and (a := input()): | n | while ans and (tmp := input()): |
| if a[:5] != 'class': | | if tmp[:5] != 'class': |
| continue | | continue |
n | a = a[6:a.find(':')] | n | tmp = tmp[6:tmp.find(':')] |
| if not a[-1] == ')': | | if not tmp[-1] == ')': |
| val = len(names) | | val = len(names) |
n | names[a] = val | n | names[tmp] = val |
| lin[val] = [val] | | lin[val] = [val] |
| continue | | continue |
n | i1 = a.find('(') | n | i1 = tmp.find('(') |
| name = a[:i1] | | name = tmp[:i1] |
| val = len(names) | | val = len(names) |
| names[name] = val | | names[name] = val |
n | a = a[i1 + 1:-1] | n | tmp = tmp[i1 + 1:-1] |
| a = a.replace(' ', '') | | tmp = tmp.replace(' ', '') |
| par = a.split(',') | | parents = tmp.split(',') |
| par = [names[i] for i in par] | | parents = [names[i] for i in parents] |
| list_ = [] | | lst = [] |
| for i in par: | | for i in parents: |
| if not i in lin: | | if not i in lin: |
| ans = False | | ans = False |
| break | | break |
n | list_.append(list(lin[i])) | n | lst.append(list(lin[i])) |
| if ans: | | if ans: |
t | list_.append(par) | t | lst.append(parents) |
| (lin[val], ans) = linear(val, list_) | | (lin[val], ans) = linear(val, lst) |
| if ans: | | if ans: |
| print('Yes') | | print('Yes') |
| else: | | else: |
| print('No') | | print('No') |