diff --git a/CPP/BFSTree.cpp b/CPP/BFSTree.cpp new file mode 100644 index 00000000..8696cac1 --- /dev/null +++ b/CPP/BFSTree.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; + +int main() { + const int N=1e5+2; + vector adj[N]; + bool vis[N]; + + int n,m; + cin>>n>>m; + for(int i=0;i>x>>y; + adj[x].push_back(y); + adj[y].push_back(x); + } + queue q; + q.push(1); + vis[1]=true; + while(!q.empty()){ + int node=q.front(); + q.pop(); + cout<:: iterator it; + for(it=adj[node].begin();it!=adj[node].end();it++){ + if(!vis[*it]){ + vis[*it]=1; + q.push(*it); + } + } + + } + + return 0; +}