#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4064 KB |
Output is correct |
2 |
Correct |
0 ms |
4064 KB |
Output is correct |
3 |
Correct |
0 ms |
4064 KB |
Output is correct |
4 |
Correct |
0 ms |
4064 KB |
Output is correct |
5 |
Correct |
0 ms |
4064 KB |
Output is correct |
6 |
Correct |
0 ms |
4064 KB |
Output is correct |
7 |
Correct |
0 ms |
4064 KB |
Output is correct |
8 |
Correct |
0 ms |
4064 KB |
Output is correct |
9 |
Correct |
0 ms |
4064 KB |
Output is correct |
10 |
Correct |
19 ms |
4064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4064 KB |
Output is correct |
2 |
Correct |
28 ms |
4064 KB |
Output is correct |
3 |
Correct |
0 ms |
4064 KB |
Output is correct |
4 |
Correct |
27 ms |
4064 KB |
Output is correct |
5 |
Correct |
57 ms |
4064 KB |
Output is correct |
6 |
Correct |
0 ms |
4064 KB |
Output is correct |
7 |
Correct |
30 ms |
4064 KB |
Output is correct |
8 |
Correct |
41 ms |
4064 KB |
Output is correct |
9 |
Correct |
40 ms |
4064 KB |
Output is correct |
10 |
Correct |
95 ms |
4064 KB |
Output is correct |