fix distance calculation and include edges that have no common neighbors with infinite distance