cycle detection using dfs