vector<int> bfsOfGraph(int v,vector<int> adj[]) { vector<int> vis(v+1,0); vis[0]=1; queue<int> q; q.push(0); vector<int> bfs; while(!q.empty()) { int node = q.front(); bfs.push_back(node); q.pop(); vis[node]=1; for(auto x:adj[node]) { if(!vis[x]){ q.push(x); vis[x]=1; } } } return bfs; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter