I cant figure out the reason for the run error and I am getting WA in 2nd testcase.
Question is- BFS - Shortest path.
Here is the code
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SIZE 200010
#define MOD 1000000007
#define BIG 998244353
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define mii map<int,int>
#define set_bit __builtin_popcount
#define tc int tcs;cin>>tcs;while(tcs–)
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ){stringstream ss; ss<< number; return ss.str();}
vector adj[10000];
bool visited[100001];
int n,m;
int parent[100001];
int dist[100001];
void bfs(int src){
queue q;
q.push(src);
visited[src]=true;
dist[src]=0;
while(!q.empty()){
int front=q.front();
q.pop();
for(auto it: adj[front]){
if(!visited[it]){
parent[it]=front;
dist[it]=dist[parent[it]]+6;
q.push(it);
}
}
}
}
int main(){
fast;
tc{
cin>>n>>m;
for (int i = 0; i <= n; ++i)
{
adj[i].clear();
}
memset(visited,false,sizeof(visited));
int u,v;
for (int i = 0; i < m; ++i)
{
cin>>u>>v;
adj[u].pb(v);
// adj[v].pb(u);
}
for (int i = 0; i <= n; ++i)
{
parent[i]=-1;
dist[i]=-1;
}
int src;
cin>>src;
bfs(src);
for (int i = 1; i <=n; ++i)
{
if(i!=src){
cout<<dist[i]<<" ";
}
}
cout<<endl;
}
return 0;
}