# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9151 |
2014-09-28T04:07:22 Z |
maniac |
Your life (kriii2_Y) |
C++ |
|
84 ms |
7712 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4416 KB |
Output is correct |
2 |
Correct |
0 ms |
4416 KB |
Output is correct |
3 |
Correct |
0 ms |
4416 KB |
Output is correct |
4 |
Correct |
0 ms |
4416 KB |
Output is correct |
5 |
Correct |
0 ms |
4416 KB |
Output is correct |
6 |
Correct |
0 ms |
4416 KB |
Output is correct |
7 |
Correct |
0 ms |
4416 KB |
Output is correct |
8 |
Correct |
0 ms |
4416 KB |
Output is correct |
9 |
Correct |
0 ms |
4416 KB |
Output is correct |
10 |
Correct |
20 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4416 KB |
Output is correct |
2 |
Correct |
40 ms |
7452 KB |
Output is correct |
3 |
Correct |
64 ms |
7452 KB |
Output is correct |
4 |
Correct |
48 ms |
7452 KB |
Output is correct |
5 |
Correct |
56 ms |
7452 KB |
Output is correct |
6 |
Correct |
36 ms |
7452 KB |
Output is correct |
7 |
Correct |
32 ms |
7452 KB |
Output is correct |
8 |
Correct |
84 ms |
7712 KB |
Output is correct |
9 |
Correct |
44 ms |
7452 KB |
Output is correct |
10 |
Correct |
72 ms |
7188 KB |
Output is correct |