Submission #9179

#TimeUsernameProblemLanguageResultExecution timeMemory
9179coreaYour life (kriii2_Y)C++14
0 / 4
0 ms3652 KiB
#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 ); } } printf( "-1\n" ); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...