closest pair algorithm to find closest pair of nodes in a graph