non-recursive dfs without checking cycles