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