Added a dfs algorithm to RES