Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <queue>
- using namespace std;
- //adj[a],push_back(b);for an edge from a to b//
- vector<int>adj[100];
- int visited[100];
- //s is the number of starting vertex//
- //n is the number of vertices (0....n-1)//
- void bfs(int s,int n)
- {
- for(int i=0; i<n; i++)visited[i]=0;
- queue<int>Q;
- Q.push(s);
- visited[s]=1;
- while(!Q.empty())
- {
- int u=Q.front();
- Q.pop();
- for(int i=0; i<adj[u].size(); i++)
- {
- if(visited[adj[u][i]]==0)
- {
- int v=adj[u][i];
- visited[v]=1;
- Q.push(v);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement