Level Wise EZ BFS without pair<int,int>


#1

int Solution::snakeLadder(vector<vector > &A, vector<vector > &B) {

int ans=0;
unordered_map<int,int>M;
for(auto e:A){
    M[e[0]]=e[1];
}
for(auto e:B){
    M[e[0]]=e[1];
}
queue<int>Q;
vector<bool>visited(101,false);
Q.push(1);
while(!Q.empty()){
    int qsize=Q.size();
    for(int i=0;i<qsize;i++){
        int u=Q.front();
        Q.pop();
        if(u==100)return ans;
        if(visited[u])continue;
        visited[u]=true;
        for(int j=1;j<=6;j++){
            int v=u+j;
            if(v>100)continue;
            if(M.find(v)!=M.end())v=M[v];
            Q.push(v);
        }
    }
    ans++;
}
return -1;

}