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 <vector>
using namespace std;
vector<int> graph[100005];
int dp[100005];
int main(){
int n,m;
scanf("%d %d",&n,&m);
while (m--) {
int x,y;
scanf("%d %d",&x,&y);
graph[y].push_back(x);
}
for (int i=2; i<=n; i++) {
dp[i] = 1e9;
for (auto &j : graph[i]){
dp[i] = min(dp[i],dp[j]+1);
}
}
if(dp[n] > n) puts("-1");
else printf("%d",dp[n]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |