Submission #13560

#TimeUsernameProblemLanguageResultExecution timeMemory
13560baneling100Your life (kriii2_Y)C++98
4 / 4
89 ms7612 KiB
#include <stdio.h>
#include <vector>
#include <queue>
#define N_MAX 100000

using namespace std;

queue <int> Q;
vector <int> Way[N_MAX+1];
int N, M, D[N_MAX+1];

int main(void) {

    int i, x, y;

    scanf("%d %d",&N,&M);
    for(i=1 ; i<=M ; i++) {
        scanf("%d %d",&x,&y);
        Way[x].push_back(y);
    }
    for(i=2 ; i<=N ; i++) D[i]=-1;
    Q.push(1);
    while(!Q.empty()) {
        x=Q.front();
        Q.pop();
        y=Way[x].size();
        for(i=0 ; i<y ; i++) if(D[Way[x][i]]==-1) {
            D[Way[x][i]]=D[x]+1;
            Q.push(Way[x][i]);
        }
    }
    printf("%d",D[N]);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...