ПУТИЛОВ ГЕОРГИЙ КОНСТАНТИНОВИЧ MroC3 11105
Тюшев Максим, 321 MroC3 10903
f1class MroChecker:f1class MroChecker:
n2    queue = {}n2    mro = {}
33
4    def __init__(self):4    def __init__(self):
n5        while (s := input()):n5        while (line := input()):
6            if s.startswith('class'):6            if line.startswith('class'):
7                name = s[6:s.find(':')]7                cls = line[6:line.find(':')]
8                if '(' in name:8                if '(' in cls:
9                    cur = name[:name.find('(')]9                    cls_name = cls[:cls.find('(')]
10                    prev = [x.strip() for x in name[name.find('(') + 1:-1].split(',')]10                    cls_decl = [x.strip() for x in cls[cls.find('(') + 1:-1].split(',')]
11                    try:11                    try:
n12                        n_q = self.mklst([self.queue[x].copy() for x in prev] + [prev])n12                        new_mro = self.build([self.mro[x].copy() for x in cls_decl] + [cls_decl])
13                    except KeyError:13                    except KeyError:
14                        print('No')14                        print('No')
15                        break15                        break
n16                    if n_q:n16                    if new_mro:
17                        self.queue[cur] = [cur] + n_q17                        self.mro[cls_name] = [cls_name] + new_mro
18                    else:18                    else:
19                        print('No')19                        print('No')
20                        break20                        break
21                else:21                else:
n22                    self.queue[name] = [name]n22                    self.mro[cls] = [cls]
23        else:23        else:
24            print('Yes')24            print('Yes')
2525
26    @staticmethod26    @staticmethod
n27    def my_extend(lists):n27    def join(lsts):
28        ans = []
29        for lst in lsts:
30            ans.extend(lst)
31        return ans
32 
33    def build(self, deps):
28        res = []34        res = []
n29        for i in lists:n
30            res.extend(i)
31        return res
32 
33    def mklst(self, deps):
34        res = []
35        fl = False35        flag = False
36        while (pars := self.my_extend(deps)):36        while (pars := self.join(deps)):
37            fl = False37            flag = False
38            for i in pars:38            for cls in pars:
39                if fl:39                if flag:
40                    break40                    break
n41                for j in deps:n41                for lst in deps:
42                    if i in j and i != j[0]:42                    if cls in lst and cls != lst[0]:
43                        break43                        break
44                else:44                else:
n45                    res.append(i)n45                    res.append(cls)
46                    fl = True46                    flag = True
47                    for j in deps:47                    for tmp in deps:
48                        if i in j:48                        if cls in tmp:
49                            j.pop(0)49                            tmp.pop(0)
50            else:50            else:
t51                if not fl:t51                if not flag:
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