def count_descendents(graph, root):
    """
    Inputs: A weighted directed acyclic `graph` with positive edge weights and a starting `root` node
    Let the weight of a path in the graph be the product of the weights of its constituent edges
    and 0 if the path is trivial with no edges
    Returns: The sum of the weights of all paths in the graph starting at the `root` node
    """
    if len(graph[root]) == 0:
        # `root` has no children, so no (paths to) descendents contributing to the sum/count
        return 0
    # Iterate over each child, multiplying by the weight of edge from root to child before recursing
    # This counts the child node itself as well as all of the higher degree descendents
    return sum(count * (1 + count_descendents(graph, node)) for node, count in graph[root].items())