getting segmentation fault
https://practice.geeksforgeeks.org/problems/snake-and-ladder-problem4816/1
// { Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution{
public:
int bfs(int x,int y,vectoradj[])
{
int dist[30]={INT_MAX};
dist[0]=0;
queue<int>q;
q.push(x);
while(!q.empty())
{
int temp=q.front();
q.pop();
for(auto it: adj[temp])
{
if(dist[it]==INT_MAX)
{
q.push(it);
dist[it]= dist[temp] + 1;
}
}
}
return dist[y];
}
void addEdge(vectoradj[],int x,int y)
{
adj[x].push_back(y);
}
int minThrow(int N, int arr[])
{
int vec[30]={0};
for(int i=0;i<N-1;i+=2)
{
vec[arr[i]]=arr[i+1] - arr[i];
}
vector<int >adj[8];
for(int i=0;i<30;i++)
{
for(int dice=1;dice<=6;dice++)
{
int j=i+dice;
j+=vec[j];
if(j<=30)
addEdge(adj,i,j);
}
}
return bfs(0,30,adj);
}
};
// { Driver Code Starts.
int main(){
int t;
cin>>t;
while(t–){
int N;
cin>>N;
int arr[2N];
for(int i = 0;i < 2N;i++)
cin>>arr[i];
Solution ob;
cout<<ob.minThrow(N, arr)<<"\n";
}
return 0;
} // } Driver Code Ends