Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bfs(int source){
- queue < int > que;
- que.push(source);
- memset(dis,-1,sizeof dis);
- dis[source] = 0;
- while(!que.empty()){
- int node = que.front();
- que.pop();
- for(int u:edg[node]){
- if(vis[u] == 0){
- que.push(u);
- dis[u] = dep[node] + 1;
- }
- }
- }
- } /// O(n+m)
Advertisement
Add Comment
Please, Sign In to add comment