distance matrix and nearest neighbor average