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 <bits/stdc++.h>
using namespace std;
struct al{
int e,nx;
}a[200010];
int st[100010],d[100010],t;
int main(){
int i,j,n,m,s,e;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i){
scanf("%d%d",&s,&e);
a[++t].nx=st[s],a[t].e=e,st[s]=t;
}
for(i=2;i<=n;++i)d[i]=1e9;
for(i=1;i<=n;++i)if(d[i]<1e9){
for(j=st[i];j;j=a[j].nx)d[a[j].e]=min(d[a[j].e],d[i]+1);
}
if(d[n]==1e9)d[n]=-1;
printf("%d",d[n]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |