This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
struct point{
int a, b;
bool operator <(const point &p)const{
return b < p.b;
}
}w[200010];
int n, m, D[200010];
int main()
{
int i;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++){
scanf("%d%d", &w[i].a, &w[i].b);
}
sort(w, w + m);
for (i = 2; i <= n; i++)D[i] = -1;
for (i = 0; i < m; i++){
if (D[w[i].a] != -1){
if (D[w[i].b] == -1 || D[w[i].b] > D[w[i].a] + 1)D[w[i].b] = D[w[i].a] + 1;
}
}
printf("%d\n", D[n]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |