This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 );
	while( !pq.empty() ) {
		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 );
		}
	}
	printf( "-1\n" );
	
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |