Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for What Is Wrong With This Family? by David_Jones
from collections import defaultdict
def is_family(tree):
ancestors = defaultdict(set)
for father, son in tree:
if (
father == son or father in ancestors[son]
or son in ancestors[father] or ancestors[father] & ancestors[son]
):
return False
ancestors[son] |= {father} | ancestors[father]
return len([person for person in ancestors if not ancestors[person]]) == 1
May 21, 2019