BFS

PHOTO EMBED

Thu May 27 2021 18:19:06 GMT+0000 (UTC)

Saved by @Randumkeng

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);
            }
        }
    }
}
content_copyCOPY