Submission #8383

#TimeUsernameProblemLanguageResultExecution timeMemory
8383tncks0121Your life (kriii2_Y)C++98
4 / 4
88 ms7108 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...