update distance matrix