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 <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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |