Make the algorithm only check visit node if it is not too far. This will safe a lot of time for big graphs.