t | def merge(*lins): | t | def merge(*lins): |
| merged = list() | | merged = list() |
| class_lins = lins | | class_lins = lins |
| st_pos = 0 | | st_pos = 0 |
| while class_lins: | | while class_lins: |
| start_el = class_lins[st_pos][0] | | start_el = class_lins[st_pos][0] |
| n = len(class_lins) | | n = len(class_lins) |
| for i in range(n): | | for i in range(n): |
| if start_el in class_lins[i] and class_lins[i].index(start_el) != 0: | | if start_el in class_lins[i] and class_lins[i].index(start_el) != 0: |
| st_pos += 1 | | st_pos += 1 |
| if st_pos == n: | | if st_pos == n: |
| return [] | | return [] |
| start_el = class_lins[st_pos][0] | | start_el = class_lins[st_pos][0] |
| break | | break |
| else: | | else: |
| merged += [start_el] | | merged += [start_el] |
| for i in range(n): | | for i in range(n): |
| if start_el in class_lins[i]: | | if start_el in class_lins[i]: |
| class_lins[i].remove(start_el) | | class_lins[i].remove(start_el) |
| class_lins = list(filter(None, class_lins)) | | class_lins = list(filter(None, class_lins)) |
| st_pos = 0 | | st_pos = 0 |
| return merged | | return merged |
| | | |
| def linearize(C1, *args): | | def linearize(C1, *args): |
| if len(args) == 1 and (not args[0]): | | if len(args) == 1 and (not args[0]): |
| return [C1] | | return [C1] |
| merged = merge(*args) | | merged = merge(*args) |
| return [C1] + merged if merged else None | | return [C1] + merged if merged else None |
| linearizations = dict() | | linearizations = dict() |
| s = input() | | s = input() |
| while s: | | while s: |
| if s.startswith('class '): | | if s.startswith('class '): |
| s = s.replace('class ', '') | | s = s.replace('class ', '') |
| s = s.replace(' ', '') | | s = s.replace(' ', '') |
| if '(' in s: | | if '(' in s: |
| class_name = s[:s.index('(')] | | class_name = s[:s.index('(')] |
| inherit_from = s[s.index('(') + 1:s.index(')')] | | inherit_from = s[s.index('(') + 1:s.index(')')] |
| inherit_from.replace(' ', '') | | inherit_from.replace(' ', '') |
| if not inherit_from: | | if not inherit_from: |
| inherit_from = [] | | inherit_from = [] |
| else: | | else: |
| inherit_from = inherit_from.split(',') | | inherit_from = inherit_from.split(',') |
| linearization = linearize(class_name, *[linearizations[key].copy() for key in inherit_from], inherit_from) | | linearization = linearize(class_name, *[linearizations[key].copy() for key in inherit_from], inherit_from) |
| if not linearization: | | if not linearization: |
| print('No') | | print('No') |
| break | | break |
| linearizations[class_name] = linearization | | linearizations[class_name] = linearization |
| else: | | else: |
| class_name = s[:s.index(':')] | | class_name = s[:s.index(':')] |
| linearizations[class_name] = [class_name] | | linearizations[class_name] = [class_name] |
| s = input() | | s = input() |
| else: | | else: |
| print('Yes') | | print('Yes') |