//single source shortest path in an unweighted graph
#include<bits/stdc++.h>
using namespace std;
template<typename T>
class graph{
map<T,list<T>>g;
public:
void addedge(int x,int y)
{
g[x].push_back(y);
g[y].push_back(x);
}
void bfs(T src)
{
map<T,int>dist;
queue<T>q;
q.push(src);
for(auto node_pair:g)
{
T node=node_pair.first;
dist[node]=INT_MAX;
}
dist[src]=0;
while(!q.empty())
{
T node=q.front();
q.pop();
for(int nbr:g[node]){
if(dist[nbr]==INT_MAX)
{
q.push(nbr);
dist[nbr]=1+dist[node];
}
}
}
for(auto node_pair:g)
{
T node=node_pair.first;
int d=dist[node];
cout<<node<<" "<<"distance:"<<d<<"\n";
}
}
};
int main()
{
graph<int>gr;
gr.addedge(0,1);
gr.addedge(1,2);
gr.addedge(2,3);
gr.addedge(3,4);
gr.addedge(4,5);
gr.bfs(0);
}