int x[1d5],y[1d5],z[1d5]; graph g; deque q; { ll@n; rd((x--,y--)(n-1)); g.setEdge(n,n-1,x,y); z[0..n-1]=-1; rep(i,n){ if(i==0||g.es[i]==1){ q.push_back(i); z[i]=0; } } while(!q.empty()){ int i=q.front(); q.pop_front(); rep[g.edge[i]](j,g.es[i]){ if(z[j]<0){ q.push_back(j); z[j]=z[i]+1; } } } wtLn(z(n)); }