44 lines
989 B
Python
44 lines
989 B
Python
from lib import get_data
|
|
from collections import defaultdict
|
|
|
|
data = get_data(__file__)
|
|
g = defaultdict(set)
|
|
|
|
for line in data.splitlines():
|
|
a, b = line.split("-")
|
|
g[a].add(b)
|
|
g[b].add(a)
|
|
|
|
|
|
cs = set()
|
|
for a, bs in g.items():
|
|
for b in bs:
|
|
for c in g[b]:
|
|
if c in bs:
|
|
cs.add(tuple(sorted([a, b, c])))
|
|
|
|
cs = [t for t in cs if any(x.startswith("t") for x in t)]
|
|
print(len(cs))
|
|
|
|
|
|
def find_largest_clique(graph):
|
|
def bron_kerbosch(r, p, x, max_clique):
|
|
if not p and not x:
|
|
if len(r) > len(max_clique[0]):
|
|
max_clique[0] = r.copy()
|
|
return
|
|
|
|
for v in p.copy():
|
|
neighbors = graph[v]
|
|
bron_kerbosch(r | {v}, p & neighbors, x & neighbors, max_clique)
|
|
p.remove(v)
|
|
x.add(v)
|
|
|
|
max_clique = [set()]
|
|
bron_kerbosch(set(), set(graph.keys()), set(), max_clique)
|
|
return max_clique[0]
|
|
|
|
|
|
cs = find_largest_clique(g)
|
|
print(",".join(sorted(cs)))
|