Submission #9426

#TimeUsernameProblemLanguageResultExecution timeMemory
9426ksmail12Your life (kriii2_Y)C++98
0 / 4
0 ms1680 KiB
#include <iostream> #include <cstdio> #include <vector> #include <queue> using namespace std; int main() { vector<vector<int> > g; vector<bool> v; queue<int> q; int n, m; int count = 0; scanf("%d %d", &n, &m); g.resize(n+1); v.resize(n+1); // make graph for (int i=m;i!=0;i--) { int x,y; scanf("%d %d", &x, &y); g[x].push_back(y); } // cout << "queue init start\n"; // find solution q.push(1); v[1] = true; // cout << "queue init\n"; while(!q.empty()) { int curr = q.front(); // cout << "curr "<< curr << endl; q.pop(); for(vector<int>::iterator it = g[curr].begin(); it!=g[curr].end();it++) { if(*it == n) { printf("%d\n", count+1); return 0; } if(!v[*it] && *it != n) { v[*it] = true; q.push(*it); } } count++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...