CPP DFS Simple solution


#1
int Solution::snakeLadder(vector<vector<int> > &a, vector<vector<int> > &b) {
    unordered_map<int,int> m;
    for(vector<int> &i : a)
    {
        m[i[0]] = i[1];
    }
    for(vector<int> &i : b)
    {
        m[i[0]] = i[1];
    }
    queue<int> q;
    q.push(1);
    int level = 1;
    vector<bool> vis(100,0); 
    while(!q.empty())
    {
        int size = q.size();
        while(size--)
        {
            int x = q.front();
            q.pop();
            for(int i=1; i<7; i++)
            {
                int finalpos = x+i;
                if(m.count(x+i))
                {
                    finalpos = m[x+i];
                }
                if(finalpos == 100)
                {
                    return level;
                }
                if(!vis[finalpos])
                {
                    vis[finalpos] = 1;
                    q.push(finalpos);
                }
                
            }
        }
        ++level;
    }
    return -1;
}

#2

this is not dfs , in dfs we use recursion / stack , whereas queue is used for bfs.