Submission #9172

# Submission time Handle Problem Language Result Execution time Memory
9172 2014-09-28T04:20:45 Z corea Your life (kriii2_Y) C++14
0 / 4
0 ms 3648 KB
#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;
}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -