답안 #9184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9184 2014-09-28T04:26:41 Z roott76 Your life (kriii2_Y) C++
0 / 4
0 ms 4020 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int N;
vector<pair<int, int> > adj[100001];

vector<int> dijkstra(int src)
{
    vector<int> dist(N, 999999999);
    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));
            }
        }
    }
    
    return dist;
}

int main()
{
    int M;
    cin >> N >> M;
    
    for(int i=0; i<M; i++)
    {
        int a, b, c = 1;
        cin >> a >> b;
        adj[a-1].push_back(make_pair(b-1, c));
    }
    
    vector<int> Dist = dijkstra(0);
    cout << Dist[N-1] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 4020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -