Simple c++ bfs solution


#1

int Solution::snakeLadder(vector<vector > &A, vector<vector > &B) {
vector visited(100,false);
queue<pair<int,int>> q;
q.push({1,0});
visited[1]=true;
while(!q.empty()){
int v = q.front().first;
int dist = q.front().second;
if(v==100) return dist;
q.pop();

    for(int j=v+1;j<=(v+6)&&j<=100;j++){
        if(!visited[j]){
            visited[j]=true;
            pair<int,int>p;
            p.first=j;
            p.second=dist+1;
            for(int i=0;i<A.size();i++){
                if(A[i][0]==j){
                    p.first=A[i][1];
                }
            }
            for(int i=0;i<B.size();i++){
                if(B[i][0]==j){
                    p.first=B[i][1];
                }
            }
            q.push(p);
        }
    }
}
return -1;

}


#2

apart from missing <int> in three places this seems fine. But this solution is giving wrong answer to

2 2 5 66 9 88 
1 2 67 8 

Any ideas what’s wrong with this code?