Modified graph traversal such that it can deal with directed graphs.