#include <cstdio>
int n,m;
int link[1005][1005];
int main()
{
for(int i=0;i<1000;i++)
for(int j=0;j<1000;j++)
link[i][j]=-1;
scanf("%d %d",&n,&m);
for(int i=0,a,b;i<m;i++){
scanf("%d %d",&a,&b);
a--;b--;
link[a][b]=1;
}
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
if(link[i][k]==-1)continue;
for(int j=0;j<n;j++){
if(link[k][j]==-1)continue;
if(link[i][j]>link[i][k]+link[k][j]||link[i][j]==-1)
link[i][j]=link[i][k]+link[k][j];
}
}
}
printf("%d",link[0][n-1]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5032 KB |
Output is correct |
2 |
Correct |
0 ms |
5032 KB |
Output is correct |
3 |
Correct |
0 ms |
5032 KB |
Output is correct |
4 |
Correct |
0 ms |
5032 KB |
Output is correct |
5 |
Correct |
0 ms |
5032 KB |
Output is correct |
6 |
Correct |
0 ms |
5032 KB |
Output is correct |
7 |
Correct |
0 ms |
5032 KB |
Output is correct |
8 |
Correct |
0 ms |
5032 KB |
Output is correct |
9 |
Correct |
0 ms |
5032 KB |
Output is correct |
10 |
Correct |
16 ms |
5032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
5028 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |