Архипов Максим, 519/2 группа MroC3 12878
ПУТИЛОВ ГЕОРГИЙ КОНСТАНТИНОВИЧ MroC3 11105
n1class MROC3:n1class MroChecker:
2    res = {}2    queue = {}
33
4    def __init__(self):4    def __init__(self):
5        while (s := input()):5        while (s := input()):
6            if s.startswith('class'):6            if s.startswith('class'):
n7                cls = s[6:s.find(':')]n7                name = s[6:s.find(':')]
8                if '(' in cls:8                if '(' in name:
9                    name = cls[:cls.find('(')]9                    cur = name[:name.find('(')]
10                    dec = [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_res = self.top([self.res[x].copy() for x in dec] + [dec])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_res:n16                    if n_q:
17                        self.res[name] = [name] + new_res17                        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.res[cls] = [cls]n22                    self.queue[name] = [name]
23        else:23        else:
24            print('Yes')24            print('Yes')
2525
26    @staticmethod26    @staticmethod
n27    def union(p):n27    def my_extend(lists):
28        val = []28        res = []
29        for k in p:29        for i in lists:
30            val.extend(k)30            res.extend(i)
31        return val31        return res
3232
n33    def top(self, arr):n33    def mklst(self, deps):
34        res = []34        res = []
n35        cnt = Falsen35        fl = False
36        while (t := self.union(arr)):36        while (pars := self.my_extend(deps)):
37            cnt = False37            fl = False
38            for cls in t:38            for i in pars:
39                if cnt:39                if fl:
40                    break40                    break
n41                for k in arr:n41                for j in deps:
42                    if cls in k and cls != k[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                    cnt = True46                    fl = True
47                    for tmp in arr: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:
n51                if cnt == False:n51                if nofl:
52                    return None52                    return None
53        return res53        return res
t54MROC3()t54MroChecker()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op