#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
bool V[ 100003 ];
vector<int> data[ 100003 ];
priority_queue< pair<int, int> > pq;
int N, M;
int main() {
scanf( "%d %d", &N, &M );
while( M -- ) {
int a, b;
scanf( "%d %d", &a, &b );
data[ a ].push_back( b );
}
pq.emplace( 0, 1 );
for( int i = 0; i < N; i ++ ) {
pair<int, int> now = pq.top();
pq.pop();
if( now.second == N ) {
printf( "%d\n", - now.first );
return 0;
}
if( V[ now.second ] ) {
continue;
}
V[ now.second ] = true;
for( auto &v : data[ now.second ] ) {
if( V[ v ] ) {
continue;
}
pq.emplace( now.first - 1, v );
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
3648 KB |
open (syscall #2) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |