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<cstdio>
#include<cassert>
#include<cstring>
#include<map>
#include<set>
#include<time.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int n, m;
vector<int> adj[100000];
const int LARGE = 987654321;
int main() {
cin.sync_with_stdio(false);
cin >> n >> m;
for(int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a; --b;
adj[a].push_back(b);
}
vector<int> c(n);
c[n-1] = 0;
for(int i = n-2; i >= 0; --i) {
c[i] = LARGE;
for(int j: adj[i])
c[i] = min(c[i], c[j] + 1);
}
cout << (c[0] == LARGE ? -1 : c[0]) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |