Skip to content

Instantly share code, notes, and snippets.

@Shafaet
Created February 23, 2014 05:37
Show Gist options
  • Save Shafaet/9167456 to your computer and use it in GitHub Desktop.
Save Shafaet/9167456 to your computer and use it in GitHub Desktop.
vector<int>G[100];
void bfs(int n,int src)
{
queue<int>Q;
Q.push(src);
int visited[100]={0},level[100];
int parent[100];
visited[src]=1;
level[src]=0;
while(!Q.empty())
{
int u=Q.front(); //Q এর সামনের নোড নিয়ে আমরা কাজ করবো
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!visited[v])
{
level[v]=level[u]+1;
parent[v]=u;
visited[v]=1;
Q.push(v);
}
}
Q.pop();
}
for(int i=1;i<=n;i++)
printf("%d to %d distance %d",src,i,level[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment