write backtracking DFS for pathfinding