#include #include #include #include using namespace std; #define mymin(x,y) ((x)<(y)?(x):(y)) #define mymax(x,y) ((x)>(y)?(x):(y)) struct edge{ int t,nxt; }a[100009]; int T,n,k; int cur,fir[50009],now[50009],s[50009],t[50009],cnt,x,y,l,r; int lp[50009],rp[50009],v[50009]; bool vis[50009]; queue q; void addedge(int from,int to){ cur++; if (fir[from]==0) fir[from]=cur; a[cur].t=to; a[now[from]].nxt=cur; now[from]=cur; } void init(){ memset(fir,0,sizeof(fir[0])*(n+5)); memset(now,0,sizeof(now[0])*(n+5)); memset(a,0,sizeof(a[0])*(cur+5)); memset(vis,0,sizeof(vis[0])*(n+5)); memset(s,0,sizeof(s[0])*(n+5)); memset(t,0,sizeof(t[0])*(n+5)); memset(v,0,sizeof(v[0])*(n+5)); cur=cnt=0; } void bfs(){ q.push(1); vis[1]=1; s[++cnt]=1; t[1]=1; while(!q.empty()){ int x=q.front(); q.pop(); for (int i=fir[x];i;i=a[i].nxt){ if (vis[a[i].t]) continue; s[++cnt]=a[i].t; q.push(a[i].t); vis[a[i].t]=1; t[a[i].t]=cnt; } } } bool chk(int lim){ memset(lp,0,sizeof(lp[0])*(n+5)); memset(rp,0,sizeof(rp[0])*(n+5)); for (int xx=n;xx>=1;xx--){ int cur=s[xx]; lp[cur]=1,rp[cur]=1000000000; if (!v[cur]){ for (int i=fir[cur];i;i=a[i].nxt){ if (t[a[i].t]v[cur] || rp[a[i].t]+lim1){ int mid=(l+r)>>1; if (chk(mid)) r=mid; else l=mid; } if (chk(l)) printf("%d\n",l); else printf("%d\n",r); } }