Cod sursa(job #2126962)

Utilizator B_RazvanBaboiu Razvan B_Razvan Data 10 februarie 2018 10:56:35
Problema Ubuntzei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <iostream>
#include <cstdio>
#include <queue>
#define NMAX 2005
#define INF 0x3f3f3f3f

using namespace std;

int N, M, K, c[NMAX], dist[NMAX];
priority_queue <pair <int, int> > Q;
vector <pair <int, int> > g[NMAX];
vector <pair <int, int> >::iterator it;

void read()
{
    scanf("%d %d", &N, &M);
    scanf("%d", &K);
    for(int i=1; i<=K; ++i)
        scanf("%d", &c[i]);
    for(int i=1; i<=M; ++i)
    {
        int x, y, c;
        scanf("%d %d %d", &x, &y, &c);
        g[x].push_back(make_pair(y, c));
        g[y].push_back(make_pair(x, c));
    }
    for(int i=2; i<=N; ++i)
        dist[i] = INF;
}

void dijkstra()
{
    Q.push(make_pair(0, 1));
    int nod, cost;
    while(!Q.empty())
    {
        nod = Q.top().second;
        cost = -1 * Q.top().first;
        Q.pop();
        if(dist[nod] == cost)
            continue;
        for(it = g[nod].begin(); it != g[nod].end(); ++it)
            if(dist[it->first] > dist[nod] + it->second)
            {
                dist[it->first] = dist[nod] + it->second;
                Q.push(make_pair(-1 * dist[it->first], it->first));
            }
    }
}

void solve()
{
    dijkstra();
    if(K == 0)
    {
        printf("%d", dist[N]);
    }
    else
    {
        return;
    }
}

int main()
{
    freopen("ubuntzei.in", "r", stdin);
    freopen("ubuntzei.out", "w", stdout);
    read();
    solve();
    return 0;
}