[algorithms][distance] check distance against 0 only when the minimum
distance is updated