GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

This Breadth first search code is not working [closed]

#include <iostream>
#include<list>
using namespace std;
list<int> *adj;
int n;
void BFS(int s){
	     bool visited[n];
	    for(int i = 0; i < n; i++)
	        visited[i] = false;
	    // Create a queue for BFS
	    list<int> queue;
	    // Mark the current node as visited and enqueue it
	    visited[s] = true;
	    queue.push_back(s);
	    while(!queue.empty())
	    {
	        // Dequeue a vertex from queue and print it
	        s = queue.front();
	        cout << s << " ";
	        queue.pop_front();
	        // Get all adjacent vertices of the dequeued vertex s
	        for(auto i:adj[s])
	        {
	            if(!visited[i])
	            {
	                visited[i] = true;
	                queue.push_back(i); //Enqueue adjacent node
	            }
	        }
	    }
}
int main() {

int q,m,x,y,s;
cin>>q;
while(q--){
	cin>>n>>m;
	adj=new list<int> [n]; //n=no. of vertices
	while(m--){ //m=no. of edges
		cin>>x>>y;
       adj[x].push_back(y);
       adj[y].push_back(x);
	}
	cin>>s;
	BFS(s);
}

	return 0;
}

Please debug this!

closed with the note: i got this
asked Jan 26 by anonymous
closed Jan 27
...