added a method to calculate the minimum distance from a category to an ancestor with a given label