Advertisement
leanchec

bfs.cpp

May 27th, 2025
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. void bfs(int ini){
  2.     queue<int> q;
  3.     q.push(ini);
  4.     visitado[0]=1;
  5.  
  6.     while(q.size()){
  7.         int cur=q.front();
  8.         q.pop();
  9.  
  10.         for(int i=0; i<(int)adj[cur].size(); i++){
  11.             int viz=adj[cur][i];
  12.             if(visitado[viz]){
  13.                 continue;
  14.             }
  15.             visitado[viz]=1;
  16.             q.push(viz);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement