#define INF 1e9 a[1<<17],*d=a+1000; v,w,n; i,j,t,m; main(){ scanf("%d",&n); for(j=1;j<100010;j++)d[j]=INF; for(i=0;i