This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
int n, m, dist[222222];
int top[111111], endp[222222], prv[222222], ecn;
int fr, rr, que[222222];
int main(){
int i, s, e;
scanf("%d%d", &n, &m);
for(i=1; i<=n; i++)top[i]=-1, dist[i]=-1;
for(i=0; i<m; i++){
scanf("%d%d", &s, &e);
endp[ecn]=e, prv[ecn]=top[s], top[s]=ecn++;
}
que[rr++]=1, dist[1]=0;
for(;fr<rr;fr++){
s=que[fr];
for(i=top[s]; i>=0; i=prv[i]){
e=endp[i];
if(dist[e]==-1){
dist[e]=dist[s]+1;
que[rr++]=e;
}
}
}
printf("%d", dist[n]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |