_no0B

Untitled

Nov 29th, 2021
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1.  
  2. void bfs(int source){
  3.     queue < int > que;
  4.     que.push(source);
  5.     memset(dis,-1,sizeof dis);
  6.     dis[source] = 0;
  7.     while(!que.empty()){
  8.         int node = que.front();
  9.         que.pop();
  10.         for(int u:edg[node]){
  11.             if(vis[u] == 0){
  12.                 que.push(u);
  13.                 dis[u] = dep[node] + 1;
  14.             }
  15.         }
  16.     }
  17. } /// O(n+m)
Advertisement
Add Comment
Please, Sign In to add comment