Чжоу Цин MroC3 11718
ПУТИЛОВ ГЕОРГИЙ КОНСТАНТИНОВИЧ MroC3 11105
f1class MroChecker:f1class MroChecker:
n2    mro = {}n2    queue = {}
33
4    def __init__(self):4    def __init__(self):
n5        while (line := input()):n5        while (s := input()):
6            if line.startswith('class'):6            if s.startswith('class'):
7                cls = line[6:line.find(':')]7                name = s[6:s.find(':')]
8                if '(' in cls:8                if '(' in name:
9                    cls_name = cls[:cls.find('(')]9                    cur = name[:name.find('(')]
10                    cls_decl = [x.strip() for x in cls[cls.find('(') + 1:-1].split(',')]10                    prev = [x.strip() for x in name[name.find('(') + 1:-1].split(',')]
11                    try:11                    try:
n12                        new_mro = self.build([self.mro[x].copy() for x in cls_decl] + [cls_decl])n12                        n_q = self.mklst([self.queue[x].copy() for x in prev] + [prev])
13                    except KeyError:13                    except KeyError:
14                        print('No')14                        print('No')
15                        break15                        break
n16                    if new_mro:n16                    if n_q:
17                        self.mro[cls_name] = [cls_name] + new_mro17                        self.queue[cur] = [cur] + n_q
18                    else:18                    else:
19                        print('No')19                        print('No')
20                        break20                        break
21                else:21                else:
n22                    self.mro[cls] = [cls]n22                    self.queue[name] = [name]
23        else:23        else:
24            print('Yes')24            print('Yes')
2525
26    @staticmethod26    @staticmethod
n27    def join(lsts):n27    def my_extend(lists):
28        ans = []28        res = []
29        for lst in lsts:29        for i in lists:
30            ans.extend(lst)30            res.extend(i)
31        return ans31        return res
3232
n33    def build(self, deps):n33    def mklst(self, deps):
34        res = []34        res = []
n35        flag = Falsen35        fl = False
36        while (pars := self.join(deps)):36        while (pars := self.my_extend(deps)):
37            flag = False37            fl = False
38            for cls in pars:38            for i in pars:
39                if flag:39                if fl:
40                    break40                    break
n41                for lst in deps:n41                for j in deps:
42                    if cls in lst and cls != lst[0]:42                    if i in j and i != j[0]:
43                        break43                        break
44                else:44                else:
n45                    res.append(cls)n45                    res.append(i)
46                    flag = True46                    fl = True
47                    for tmp in deps:47                    for j in deps:
48                        if cls in tmp:48                        if i in j:
49                            tmp.pop(0)49                            j.pop(0)
50            else:50            else:
t51                if not flag:t51                if not fl:
52                    return None52                    return None
53        return res53        return res
54MroChecker()54MroChecker()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op