BUG: fix validation in csgraph.shortest_path

This should fix #3466