same thing using distance matrix