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>
std::vector<int> route[100000];
int length[100000];
int main(void)
{
std::queue<int> queue;
int N, M, x, y, min = -1;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++)
{
scanf("%d %d", &x, &y);
route[x - 1].push_back(y - 1);
}
queue.push(0);
for (int l = 0; !queue.empty(); l++)
{
int size = queue.size();
for (int i = 0; i < size; i++)
{
int n = queue.front();
queue.pop();
if (length[n] != 0 && length[n] < l)
{
continue;
}
length[n] = l;
if (n == N - 1)
{
min = l;
goto END;
}
for (int j = 0; j < route[n].size(); j++)
{
queue.push(route[n][j]);
}
}
}
END:
printf("%d", min);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |