bst weighted path length function