Submission #9182

#TimeUsernameProblemLanguageResultExecution timeMemory
9182coreaYour life (kriii2_Y)C++14
4 / 4
88 ms6952 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 ); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...