Fix bug in shortest_distance() with "directed" parameter

This fixes issue #300
6 jobs for master