shortest path work on small directed and undirected