Advertisement
Mashrur

Untitled

Apr 2nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<int> grph[10000];
  6. int node, edge;
  7. int level[10000];
  8. int visited[10000];
  9.  
  10.  
  11. int BFS(int source, int destination){
  12.     visited[source] = 1;
  13.     level[source] = 0;
  14.  
  15.     queue<int> q;
  16.     q.push(source);
  17.     while(!q.empty()){
  18.         int x = q.front();
  19.         q.pop();
  20.         for(int i = 0; i < grph[x].size(); i++){
  21.             int y = grph[x][i];
  22.             if(visited[y] == 0){
  23.                 visited[y] = 1;
  24.                 if(level[y] == 0){
  25.                     level[y] = level[x] + 1;
  26.                     q.push(y);
  27.                 }
  28.                
  29.             }
  30.         }
  31.     }
  32.     return level[destination];
  33. }
  34.  
  35.  
  36. int main(){
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement