Submission #9159

#TimeUsernameProblemLanguageResultExecution timeMemory
9159pichuliaYour life (kriii2_Y)C++98
4 / 4
88 ms11404 KiB
#include<stdio.h> #include<algorithm> #include<vector> using namespace std; typedef pair<int, int> pii; int n,m; int d[200000]; int queue[200000]; int q,r; vector<int> v[200000]; int mark[200000]; int main() { scanf("%d %d",&n,&m); int i, j, k; for(i=0;i<n;i++) d[i] = 1000000000; queue[0] = 0; q=0;r=1; while(m--) { scanf("%d %d",&i,&j); i--;j--; v[i].push_back(j); } d[0] = 0; while(q<r) { int qi = queue[q]; for(i=0;i<v[qi].size();i++) { j = v[qi][i]; if(d[j] > d[qi]+1) { d[j] = d[qi]+1; queue[r] = j; r++; } } q++; } if(d[n-1] > 999999999)d[n-1] = -1; printf("%d\n",d[n-1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...