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<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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |