def root_to_leaf(input_weights, taxa_tree):
    """Return a dictionary mapping taxa to weights.

    Each output weight should be the sum of input weights
    for a taxa and all of its ancestor taxa up to the 'root'
    of the tree.

    Use `taxa_tree.ancestors(<taxon>)` to get a list of ancestors for taxon.
    """
    output_weights = {}
    for taxon, weight in input_weights.items():
        for ancestor in taxa_tree.ancestors(taxon):
            out_weight = output_weights.get(taxon, 0)
            output_weights[taxon] = out_weight + input_weights.get(ancestor, 0)
    return output_weights