#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]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3036 KB |
Output is correct |
2 |
Correct |
0 ms |
3036 KB |
Output is correct |
3 |
Correct |
0 ms |
3036 KB |
Output is correct |
4 |
Correct |
1 ms |
3036 KB |
Output is correct |
5 |
Correct |
0 ms |
3036 KB |
Output is correct |
6 |
Correct |
0 ms |
3036 KB |
Output is correct |
7 |
Correct |
0 ms |
3036 KB |
Output is correct |
8 |
Correct |
0 ms |
3036 KB |
Output is correct |
9 |
Correct |
0 ms |
3036 KB |
Output is correct |
10 |
Correct |
34 ms |
3036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3036 KB |
Output is correct |
2 |
Correct |
37 ms |
3036 KB |
Output is correct |
3 |
Correct |
62 ms |
3036 KB |
Output is correct |
4 |
Correct |
62 ms |
3036 KB |
Output is correct |
5 |
Correct |
38 ms |
3036 KB |
Output is correct |
6 |
Correct |
48 ms |
3036 KB |
Output is correct |
7 |
Correct |
37 ms |
3036 KB |
Output is correct |
8 |
Correct |
74 ms |
3036 KB |
Output is correct |
9 |
Correct |
57 ms |
3036 KB |
Output is correct |
10 |
Correct |
75 ms |
3036 KB |
Output is correct |