graph: fix potential dfs bug