#include #include using namespace std; int main() { int nodes; cout<<"Enter Node Number: "<> nodes; int graph[nodes][nodes]; int edges; cout<<"Enter Edge Number: "<> edges; //Graph initialization for(int i=0; i> v1 >> v2; graph[v1][v2]=1; // Unweighted with 2 line is undirected graph[v2][v1]=1; // This line for directed (Not using this line means directed) } /* //Graph input with weight for (int i=0; i> v1 >> v2 >> w; graph[v1][v2]= w; // Weighted with 2 line is undirected graph[v2][v1]= w; // This line for directed (Not using this line means directed) } */ //Print matrix for(int i=0; i> root; queue q; q.push(root); int visited[nodes] = {0}; while(!q.empty()) { int node = q.front(); q.pop(); if(visited[node]) continue; cout<< node<< " "; visited[node] =1; for(int adj_node=0; adj_node0 && !visited[adj_node]) { q.push(adj_node); } } } }