Free-energy cost for ultrametricity violations in spin glasses