#include <stdio.h>
#include <vector>
#include <queue>
#define N_MAX 100000
using namespace std;
queue <int> Q;
vector <int> Way[N_MAX+1];
int N, M, D[N_MAX+1];
int main(void) {
int i, x, y;
scanf("%d %d",&N,&M);
for(i=1 ; i<=M ; i++) {
scanf("%d %d",&x,&y);
Way[x].push_back(y);
}
for(i=2 ; i<=N ; i++) D[i]=-1;
Q.push(1);
while(!Q.empty()) {
x=Q.front();
Q.pop();
y=Way[x].size();
for(i=0 ; i<y ; i++) if(D[Way[x][i]]==-1) {
D[Way[x][i]]=D[x]+1;
Q.push(Way[x][i]);
}
}
printf("%d",D[N]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4316 KB |
Output is correct |
2 |
Correct |
0 ms |
4316 KB |
Output is correct |
3 |
Correct |
0 ms |
4316 KB |
Output is correct |
4 |
Correct |
0 ms |
4316 KB |
Output is correct |
5 |
Correct |
0 ms |
4316 KB |
Output is correct |
6 |
Correct |
0 ms |
4316 KB |
Output is correct |
7 |
Correct |
0 ms |
4316 KB |
Output is correct |
8 |
Correct |
0 ms |
4316 KB |
Output is correct |
9 |
Correct |
0 ms |
4316 KB |
Output is correct |
10 |
Correct |
0 ms |
4848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4316 KB |
Output is correct |
2 |
Correct |
45 ms |
7352 KB |
Output is correct |
3 |
Correct |
60 ms |
7352 KB |
Output is correct |
4 |
Correct |
45 ms |
7352 KB |
Output is correct |
5 |
Correct |
37 ms |
7352 KB |
Output is correct |
6 |
Correct |
41 ms |
7352 KB |
Output is correct |
7 |
Correct |
35 ms |
7352 KB |
Output is correct |
8 |
Correct |
89 ms |
7612 KB |
Output is correct |
9 |
Correct |
51 ms |
7352 KB |
Output is correct |
10 |
Correct |
76 ms |
7088 KB |
Output is correct |