Fast calculation of the quartet distance between trees of arbitrary degrees