Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple check solution in Clear category for What Is Wrong With This Family? by kdim
def is_family(tree):
f, s = zip(*tree)
if len(set(f) - set(s)) != 1: return False # root must be one
if len(s) != len(set(s)): return False # every son should be unique name
fs = [set(fs) for fs in tree]
for i, j in enumerate(fs):
if len(j) != 2: return False # father and son must be different name
if j in fs[:i] + fs[i+1:]: return False # the son should not be the father of his father
return True
Jan. 21, 2021
Comments: