Find clusters based on distance matrix or similarity matrix.