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 <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int dp[100001];
int M, N;
typedef pair<int, int> PAIR;
bool cmp(PAIR x, PAIR y)  {
	if (x.first < y.first){
		return true;
	}
	else if (x.first == y.first) {
		return x.second < y.second;
	}
	else {
		return false;
	}
}
int main(void) {
	int x, y;
	vector<PAIR> edge;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> x >> y;
		edge.push_back(PAIR(x, y));
	}
	sort(edge.begin(), edge.end(), cmp);
	for (vector<PAIR>::iterator itor = edge.begin(); itor != edge.end(); itor++) {
		x = itor->first; y = itor->second;
		if (x != 1 && dp[x] == 0) continue;
		if (dp[y] == 0) {
			dp[y] = dp[x] + 1;
		}
		else if (dp[y] > dp[x] + 1){
			dp[y] = dp[x] + 1;
		}
	}
	cout << dp[N] << endl;
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |