Submission #9541

#TimeUsernameProblemLanguageResultExecution timeMemory
9541jaehadadYour life (kriii2_Y)C++14
4 / 4
92 ms7704 KiB
#include<cstdio> #include<cassert> #include<cstring> #include<map> #include<set> #include<time.h> #include<algorithm> #include<stack> #include<queue> #include<utility> #include<cmath> #include<iostream> #include<string> #include<vector> using namespace std; int n, m; vector<int> adj[100000]; const int LARGE = 987654321; int main() { cin.sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a; --b; adj[a].push_back(b); } vector<int> c(n); c[n-1] = 0; for(int i = n-2; i >= 0; --i) { c[i] = LARGE; for(int j: adj[i]) c[i] = min(c[i], c[j] + 1); } cout << (c[0] == LARGE ? -1 : c[0]) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...