| 9 | queue<int> q; |
| 10 | |
| 11 | void bfs(int sour) |
| 12 | { |
| 13 | for(int i=1;i<=n;i++) |
| 14 | { |
| 15 | if(n!=1) |
| 16 | { |
| 17 | parent[i]=0; |
| 18 | dist[i]=-1; |
| 19 | } |
| 20 | } |
| 21 | parent[sour]=0; |
| 22 | dist[sour]=0; |
| 23 | q.push(sour); |
| 24 | while(!q.empty()) |
| 25 | { |
| 26 | int x=q.front(); |
| 27 | q.pop(); |
| 28 | for(int j=0;j<adjList[x].size();j++) |
| 29 | { |
| 30 | int v=adjList[x][j]; |
| 31 | if(parent[v]==0) |
| 32 | { |
| 33 | dist[v]=dist[x]+1; |
| 34 | parent[v]=x; |
| 35 | q.push(v); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | int main() |
| 42 | { |
no test coverage detected