For each vertex (node) of the linear network,
  this algorithm finds the nearest data point to the vertex,
  and returns either the distance from the vertex to its nearest
  neighbour in X, or the serial number of the nearest neighbour
  in X, or both.
If k is an integer, then the k-th nearest neighbour
  is found instead.
If k is an integer vector, this is repeated for each
  integer in k.