Submission #16521

#TimeUsernameProblemLanguageResultExecution timeMemory
16521hongjun7Your life (kriii2_Y)C++98
4 / 4
75 ms3036 KiB
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; int d[100005]; pair <int, int> p[200005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &p[i].first, &p[i].second); } sort(p + 1, p + m + 1); for (int i = 1; i <= n; i++) d[i] = -1; d[1] = 0; for (int i = 1; i <= m; i++) { int a = p[i].first, b = p[i].second; if (d[a] != -1) if (d[b] == -1 || d[b] > d[a] + 1) d[b] = d[a] + 1; } printf("%d", d[n]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...