Submission #9151

#TimeUsernameProblemLanguageResultExecution timeMemory
9151maniacYour life (kriii2_Y)C++98
4 / 4
84 ms7712 KiB
#include<cstdio> #include<cassert> #include<cstring> #include<map> #include<set> #include<time.h> #include<algorithm> #include<stack> #include<queue> #include<utility> #include<cmath> #include<iostream> #include<string> #include<vector> #include<limits> using namespace std; long long gcd( long long b, long long s ){ return (s!=0) ? gcd( s, b%s ) : b; } const int N = 100005; const int INF = 1000000007; vector <int> e[N]; int d[N]; int main(){ int n, m; scanf("%d %d", &n, &m); for(int i=0; i<m; i++){ int x, y; scanf("%d %d", &x, &y); e[x].push_back( y ); } queue <int> q; for(int i=1; i<=n; i++) d[i] = INF; q.push( 1 ); d[1] = 0; while( !q.empty() ){ int p = q.front(); q.pop(); for(int i=0; i<e[p].size(); i++){ int u = e[p][i]; if( d[p]+1 < d[u] ){ d[u] = d[p] + 1; q.push( u ); } } } if( d[n] != INF ) printf("%d\n", d[n]); else puts("-1"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...