#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6676 KB |
Output is correct |
2 |
Correct |
0 ms |
6676 KB |
Output is correct |
3 |
Correct |
0 ms |
6676 KB |
Output is correct |
4 |
Correct |
0 ms |
6676 KB |
Output is correct |
5 |
Correct |
0 ms |
6676 KB |
Output is correct |
6 |
Correct |
0 ms |
6676 KB |
Output is correct |
7 |
Correct |
0 ms |
6676 KB |
Output is correct |
8 |
Correct |
0 ms |
6676 KB |
Output is correct |
9 |
Correct |
0 ms |
6676 KB |
Output is correct |
10 |
Correct |
20 ms |
7212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6676 KB |
Output is correct |
2 |
Correct |
40 ms |
9712 KB |
Output is correct |
3 |
Correct |
56 ms |
9712 KB |
Output is correct |
4 |
Correct |
56 ms |
9712 KB |
Output is correct |
5 |
Correct |
52 ms |
9712 KB |
Output is correct |
6 |
Correct |
32 ms |
9712 KB |
Output is correct |
7 |
Correct |
32 ms |
9712 KB |
Output is correct |
8 |
Correct |
80 ms |
9844 KB |
Output is correct |
9 |
Correct |
48 ms |
9712 KB |
Output is correct |
10 |
Correct |
72 ms |
9448 KB |
Output is correct |