#include #include #include #include using namespace std; int main(){ int n; cin >> n; assert(2<=n && n<=100000); vector> G(n); for(int i=0; i> x >> y; assert(1<=x); assert(x< y); assert(y<=n); x--; y--; G[x].push_back(y); G[y].push_back(x); } vector dist(n, 1e8); queue q; q.push(0); dist[0] = 0; for(int i=1; i dist[pos]+1){ dist[to] = dist[pos]+1; q.push(to); } } } for(int i=0; i