def _dfs(root, child_func):
    """
    Returns a list of elements in DFS order from a given root node.
    :param root: root element
    :param child_func: mapping to children of each element
    :return: DFS ordered list of elements including root
    """
    visited, stack = set(), [root]
    while stack:
        current = stack.pop()
        if current not in visited:
            visited.add(current)
            stack.extend([child for child in child_func(current) if child not in visited])
    return list(visited)