ll vis[maxn],in[maxn],out[maxn],dis[maxn]; vector<ll> adj[maxn] ; queue<ll> q ; void bfs(ll u) { q.push(u); vis[u]=1; dis[u]=0; while(!q.empty()) { ll qfront = q.front(); q.pop(); cout<<qfront<<" "<<dis[qfront]<<"\n"; for(auto v:adj[qfront]) { if(!vis[v]) { vis[v]=1; dis[v]=dis[qfront]+1; q.push(v); } } } }
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