bfs模板

queue<int> q;        //建立队列 
q.push(i);            //入队 
while(!q.empty()){    //非空判断 
    int sz=q.size();
    while(sz-->0){    //当前层 
        int t=q.front();    //出队 
        q.pop();
        vis[t]=1;            //出队已访问 
        FF(k,g[t].size()){    //出队顶点的所有后继 
            int tmp=g[t][k];
            if(vis[tmp]==0){    //入队访问判断
                q.push(tmp);    //入队 
                vis[tmp]=1;        //入队已访问 
            } 
        }
    }
}
原文地址:https://www.cnblogs.com/TQCAI/p/8523123.html