Wrote function to find the greatest cost of the tree