Cod sursa(job #1008272)

Utilizator mvcl3Marian Iacob mvcl3 Data 10 octombrie 2013 18:57:04
Problema Ubuntzei Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
//Solutie 20 puncte

#include <fstream>
#include <vector>
#include <queue>
#include <string.h>
#define IN "ubuntzei.in"
#define OUT "ubuntzei.out"
#define MAX_SIZE 2009
#define oo 1000000

std :: ifstream f(IN);
std :: ofstream g(OUT);

int N, M, K;
int VIZ[MAX_SIZE], BestD[MAX_SIZE];
std :: vector < std :: pair < int, int > > V[MAX_SIZE];
std :: queue < int > Q;

inline void READ_DATA()
{
    int a;
    f >> N >> M >> K;
    for(int i = 1; i <= K; ++i) f >> a;

    int x, y, z;
    for(int i = 1; i <= M; ++i)
    {
        f >> x >> y >> z;
        V[x].push_back(std :: make_pair(y, z));
        V[y].push_back(std :: make_pair(x, z));
    }
}

void BF()
{
    int nod;
    std :: vector < std :: pair < int, int > > :: iterator it;
    Q.push(1);
    BestD[1] = 0;

    while(!Q.empty())
    {
        nod = Q.front();
        Q.pop();
        for(it = V[nod].begin(); it != V[nod].end(); ++it)
            if(BestD[(*it).first] > BestD[nod] + (*it).second)
            {
                BestD[(*it).first] = BestD[nod] + (*it).second;
                Q.push((*it).first);
            }
    }
}

int main()
{
    READ_DATA();
    memset(BestD, oo, sizeof(BestD));
    BF();

    g << BestD[N] << '\n';

    g.close();
    return 0;
}