This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |