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 <algorithm>
using namespace std;
int d[100005];
pair <int, int> p[200005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &p[i].first, &p[i].second);
}
sort(p + 1, p + m + 1);
for (int i = 1; i <= n; i++) d[i] = -1;
d[1] = 0;
for (int i = 1; i <= m; i++) {
int a = p[i].first, b = p[i].second;
if (d[a] != -1) if (d[b] == -1 || d[b] > d[a] + 1) d[b] = d[a] + 1;
}
printf("%d", d[n]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |