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<cstdio>
#include<vector>
std::vector<int> a[200001];
int d[200001];
int main()
{
int n,m;
int i,j,x,y;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
a[x].push_back(y);
}
for(i=1;i<=n;i++)d[i]=2e9;
d[1]=0;
for(i=1;i<=n;i++)for(j=0;j<a[i].size();j++)if(d[a[i][j]]>d[i]+1)d[a[i][j]]=d[i]+1;
printf("%d",d[n]<1e9?d[n]:-1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |