finding shortest path using dfs