Efficient Optimization of Monotonic Functions on Trees