Adaptive Algorithms for Weighted Queries on Weighted Binary Relations and Labeled Trees