#include #include #include using namespace std; int n,m,dist[10000]; vector gr[10000]; ///gr - array of vectors of ints, gr[i]-vector of ints, gr[i][j] - int bool used[10000]; void init(){ int from,to; scanf("%d %d",&n,&m);///number of vertices and number of edges for(int i=0;ito) gr[to].push_back(from);///only if the graph is undirected. from becomes a neighbor of to. (since the edge is two way). If this row is skipped the graph becomes directed } } ///breath first search void bfs(int start){ queuetoVisit; int node; toVisit.push(start);///add the starting vertice to the queue used[start]=1;///mark it as visited (since the algorithm requires that a vertice is marked as visited as soon as it enters the queue) dist[start]=0;///the distance to the starting node is 0 (since we start there) while(!toVisit.empty()){///while there are vertices to be visited node = toVisit.front();///take one toVisit.pop();///remove it from queue printf("%d ",node); for(int i=0;i