f | import re | f | import re |
t | | t | |
| Cls, L = {}, {} | | Cls, L = {}, {} |
| | | |
| | | |
| def merge(mros): | | def merge(mros): |
| if not mros: | | if not mros: |
| return | | return |
| S = [L.setdefault(c, [c, *merge(Cls[c])]).copy() for c in mros] + [mros] | | S = [L.setdefault(c, [c, *merge(Cls[c])]).copy() for c in mros] + [mros] |
| while S: | | while S: |
| for s in S: | | for s in S: |
| if not s: | | if not s: |
| continue | | continue |
| e = s[0] | | e = s[0] |
| if all(e == ss[0] or e not in ss for ss in S): | | if all(e == ss[0] or e not in ss for ss in S): |
| yield e | | yield e |
| for ss in S: | | for ss in S: |
| if ss and ss[0] == e: | | if ss and ss[0] == e: |
| del ss[0] | | del ss[0] |
| S = list(filter(len, S)) | | S = list(filter(len, S)) |
| break | | break |
| else: | | else: |
| raise TypeError | | raise TypeError |
| | | |
| | | |
| reClass = re.compile(r"class\s+(\w+)\s*(?:\((.*)\))?\s*:") | | reClass = re.compile(r"class\s+(\w+)\s*(?:\((.*)\))?\s*:") |
| s = input().rstrip() | | s = input().rstrip() |
| while s: | | while s: |
| res = reClass.match(s) | | res = reClass.match(s) |
| if res: | | if res: |
| Nam, Par = res.groups() | | Nam, Par = res.groups() |
| Cls[Nam] = [c.strip() for c in Par.split(",")] if Par else [] | | Cls[Nam] = [c.strip() for c in Par.split(",")] if Par else [] |
| try: | | try: |
| L[Nam] = [Nam, *merge(Cls[Nam])] | | L[Nam] = [Nam, *merge(Cls[Nam])] |
| except TypeError: | | except TypeError: |
| print("No") | | print("No") |
| break | | break |
| s = input().rstrip() | | s = input().rstrip() |
| else: | | else: |
| print("Yes") | | print("Yes") |
| | | |