MroC3/Stephan
MroC3/yervandsargsyan
f1import ref1import re
t2 t
3Cls, L = {}, {}2Cls, L = {}, {}
43
54
6def merge(mros):5def merge(mros):
7    if not mros:6    if not mros:
8        return7        return
9    S = [L.setdefault(c, [c, *merge(Cls[c])]).copy() for c in mros] + [mros]8    S = [L.setdefault(c, [c, *merge(Cls[c])]).copy() for c in mros] + [mros]
10    while S:9    while S:
11        for s in S:10        for s in S:
12            if not s:11            if not s:
13                continue12                continue
14            e = s[0]13            e = s[0]
15            if all(e == ss[0] or e not in ss for ss in S):14            if all(e == ss[0] or e not in ss for ss in S):
16                yield e15                yield e
17                for ss in S:16                for ss in S:
18                    if ss and ss[0] == e:17                    if ss and ss[0] == e:
19                        del ss[0]18                        del ss[0]
20                S = list(filter(len, S))19                S = list(filter(len, S))
21                break20                break
22        else:21        else:
23            raise TypeError22            raise TypeError
2423
2524
26reClass = re.compile(r"class\s+(\w+)\s*(?:\((.*)\))?\s*:")25reClass = re.compile(r"class\s+(\w+)\s*(?:\((.*)\))?\s*:")
27s = input().rstrip()26s = input().rstrip()
28while s:27while s:
29    res = reClass.match(s)28    res = reClass.match(s)
30    if res:29    if res:
31        Nam, Par = res.groups()30        Nam, Par = res.groups()
32        Cls[Nam] = [c.strip() for c in Par.split(",")] if Par else []31        Cls[Nam] = [c.strip() for c in Par.split(",")] if Par else []
33        try:32        try:
34            L[Nam] = [Nam, *merge(Cls[Nam])]33            L[Nam] = [Nam, *merge(Cls[Nam])]
35        except TypeError:34        except TypeError:
36            print("No")35            print("No")
37            break36            break
38    s = input().rstrip()37    s = input().rstrip()
39else:38else:
40    print("Yes")39    print("Yes")
4140
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op