Wrong answer in online editor

#include<bits/stdc++.h>
using namespace std;
#define f(i,n)for(i=1;i<=n;i++)
template
class graph
{
private:
int v;
map<t,list > adjlist;
public:
graph(int v){
this->v=v;
}
void addedge(t u,t v,bool bidir=true)
{
adjlist[u].push_back(v);
if(bidir)
adjlist[v].push_back(u);
}
void print()
{
typename map<t,list >::iterator it;
typename list::iterator jt;
for(it=adjlist.begin();it!=adjlist.end();it++)
{
cout<first<<"->";
for(jt=it->second.begin();jt!=it->second.end();jt++)
cout<<*jt<<",";
cout<<"\n";
}
}
void bfs(t src)
{
cout<<v<<"\n";
map<t,bool>visited;
// cout<<“1 2\n”;
int dist[v+1],i;
typename map<t,list >::iterator it;
for(i=1;i<=v;i++)
dist[i]=-1;
// f(i,v)cout<<dist[i]<<" “;
queueq;
q.push(src);
visited[src]=true;
dist[src]=0;
while(!q.empty())
{
t node=q.front();
q.pop();
typename list::iterator jt;
for(jt=adjlist[node].begin();jt!=adjlist[node].end();jt++)
{
if(!visited[*jt])
{
q.push(*jt);
visited[*jt]=true;
dist[*jt]=dist[node]+6;
}
}
}
for(i=1;i<=v;i++)
if(i!=src)
cout<<dist[i]<<” “;
}
};
main()
{
int q;
cin>>q;
while(q–)
{
int n,m,src;
cin>>n>>m;
graph g(n);
int u,v;
for(int i=0;i<m;i++)
{
cin>>u>>v;
g.addedge(u,v,true);
}
cin>>src;
g.bfs(src);
cout<<”\n";
}
}

you have made a lot of syntax errors, and printed stuff which was not required, such as
cout << v << “\n” in the bfs function was not required.
after correcting all syntax errors, your code gives correct output for the sample input.

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.