This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
const int N_ = 100005;
int N, M;
vector<int> Gph[N_];
int table[N_];
int main() {
scanf("%d%d", &N, &M);
assert(1 <= N && N <= 100000);
assert(0 <= M && M <= 200000);
while(M--) {
int x, y; scanf("%d%d", &x, &y);
Gph[x].push_back(y);
assert(1 <= x && x < y && y <= N);
}
for(int i = 2; i <= N; i++) table[i] = N+1;
for(int u = 1; u <= N; u++) if(table[u] < N+1) {
for(int i = 0; i < Gph[u].size(); i++) table[Gph[u][i]] = min(table[Gph[u][i]], table[u]+1);
}
if(table[N] > N) table[N] = -1;
printf("%d\n", table[N]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |