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