Bfs-shortest path

don’t know why getting segmentation fault error int this
#include <bits/stdc++.h>
using namespace std;
class graph{
listl;
int v;
public:
graph(int v){
this->v=v;
l=new list[v];
}
void addEdge(int x,int y)
{
l[x].push_back(y);
l[y].push_back(x);
}
void dijkstra(int src,int n)
{
unordered_map<int,int>dis;
for(int i=1;i<=n;i++){
dis[i]=INT_MAX;
}
set<pair<int,int> >s;
dis[src]=0;
s.insert(make_pair(0,src));
while(!s.empty())
{
auto p=
(s.begin());
s.erase(s.begin());
int node=p.second;
int dis_node=p.first;
for(int nbr:l[node])
{
if(dis_node+ 6 < dis[nbr])
{
//we will update the distance
//first we see if it it there from before so we replace and update it
auto f=s.find(make_pair(dis[nbr],nbr));
if(f!=s.end())
{
s.erase(f);
}
dis[nbr]=dis_node + 6;
s.insert(make_pair(dis[nbr],nbr));
}
}
}
for(int i=1;i<=n;i++)
{
if(i!=src)
{
if(dis[i]!=INT_MAX)
{
cout<<dis[i]<<" “;
}
else{
cout<<”-1"<<" ";
}
}
}
}

};
int main() {
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
graph g(n);
for(int i=1;i<m;i++)
{
int x,y;
cin>>x>>y;
g.addEdge(x,y);
}
int src;
cin>>src;
g.dijkstra(src,n);
cout<<endl;
}
return 0;
}
please check it out

@Saurabh2771999 please share your code by saving it on ide.codingblocks.com

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.