def get_all_descendants(root, children_map):
    """
    Returns all descendants in the tree of a given root node, recursively
    visiting them based on the map from parents to children.
    """
    return {root}.union(
        *[get_all_descendants(child, children_map)
            for child in children_map.get(root, [])]
    )