Finding distances between points that share a common coordinate given the graph