
function s = sum (f, R, parent)
    [_, i] = sort(f(:), "descend");
    
    s = f;
    
    for x = i'
        if x != parent(x)
            s(parent(x)) = s(parent(x)) + s(x);
        end
    end
end
