Snake and ladders

#include<bits/stdc++.h>
using namespace std;

template
class graph{
int v;
map<T,list>m;

public:

graph(int v){
this->v=v;

}
void addedge(int x,int y){
m[x].push_back(y);
// m[y].push_back(x);

}

void bfsshortest(T src,T dest){

 map<T,int>dist;
 bool visited[v];
 for(auto p:m){
	 dist[p.first]=-1;
    visited[p.first]=false;
 }

 queue<T>q;
 q.push(src);
 dist[src]=0;
 visited[src]=true;
 while(!q.empty()){
   
   T node=q.front();

   q.pop();
   visited[node]=true;
   for(auto p:m[node]){
	   if(!visited[p]){
         q.push(p);
		   dist[p]=dist[node]+1;
		   visited[p]=true;
	   }
    
   }
 }

}

};
int main() {

int t;
cin>>t;

while(t--){
	int n,l,s;
	cin>>n;
	cin>>l;
	cin>>s;
	int board[n]={0};
	graph<int> g(n);
	int k=l+s;
	while(k--){
		int x,y;
		cin>>x>>y;
		board[x]=y-x;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=6;j++){
			int k=i+j;
			 k=k+board[k];
			 g.addedge(i,k);
		}
	}
	g.bfsshortest(1,n);
}
return 0;

}

segmentation fault

hi @kumarakash121005, here;'s the upadted and commented code https://ide.codingblocks.com/s/661258

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.