Submission #9226

#TimeUsernameProblemLanguageResultExecution timeMemory
9226kkjjkkYour life (kriii2_Y)C++98
4 / 4
96 ms10876 KiB
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<queue> #include<deque> using namespace std; const int MAX_V = 200005; const int INF = 987654321; int V; vector<pair<int, int> > adj[MAX_V]; vector<int> dijkstra(int src) { vector<int> dist(V, INF); dist[src] = 0; priority_queue<pair<int, int> > pq; pq.push(make_pair(0, src)); while(!pq.empty()) { int cost = -pq.top().first; int here = pq.top().second; pq.pop(); if(dist[here] < cost) continue; for(int i = 0; i < adj[here].size(); ++i) { int there = adj[here][i].first; int nextDist = cost + adj[here][i].second; if(dist[there] > nextDist) { dist[there] = nextDist; pq.push(make_pair(-nextDist, there)); } } } if(dist[V - 1] == INF) printf("-1"); else printf("%d", dist[V - 1]); return dist; } int main() { int n, m; scanf("%d %d", &n, &m); V = n + 1; for(int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); adj[a].push_back(make_pair(b, 1)); } dijkstra(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...