Submission #9158

#TimeUsernameProblemLanguageResultExecution timeMemory
9158myungwooYour life (kriii2_Y)C++14
4 / 4
56 ms4992 KiB
#include<stdio.h>

int n, m, dist[222222];
int top[111111], endp[222222], prv[222222], ecn;
int fr, rr, que[222222];

int main(){
	int i, s, e;
	scanf("%d%d", &n, &m);
	for(i=1; i<=n; i++)top[i]=-1, dist[i]=-1;
	for(i=0; i<m; i++){
		scanf("%d%d", &s, &e);
		endp[ecn]=e, prv[ecn]=top[s], top[s]=ecn++;
	}
	que[rr++]=1, dist[1]=0;
	for(;fr<rr;fr++){
		s=que[fr];
		for(i=top[s]; i>=0; i=prv[i]){
			e=endp[i];
			if(dist[e]==-1){
				dist[e]=dist[s]+1;
				que[rr++]=e;
			}
		}
	}
	printf("%d", dist[n]);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...