Cod sursa(job #1074916)

Utilizator pulseOvidiu Giorgi pulse Data 8 ianuarie 2014 09:49:18
Problema Ubuntzei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <fstream>
#include <vector>
#include <queue>
#define INF 0x3f3f3f3f

using namespace std;

ifstream fin ("ubuntzei.in"); ofstream fout ("ubuntzei.out");

int N, M, k, cost[2002], c[2002];
vector <pair <int, int> > v[2002];
queue <long int> q;

void bellman ()
{
    q.push (1);
    cost[1] = 0;
    while (!q.empty ())
    {
        int x = q.front ();
        q.pop ();
        for (int i = 0; i < v[x].size (); ++i)
        {
            if (cost[v[x][i].first] > cost[x] + v[x][i].second)
            {
                cost[v[x][i].first] = cost[x] + v[x][i].second;
                q.push (v[x][i].first);
            }
        }
    }
}

int main ()
{
    fin >> N >> M >> k;
    for (int i = 1; i <= k; ++i)
        fin >> c[i];
    for (int i = 1, A, B, C; i <= M; ++i)
    {
        fin >> A >> B >> C;
        v[A].push_back (make_pair(B, C));
        v[B].push_back (make_pair(A, C));
    }
    for (int i = 1; i <= N; ++i)
        cost[i] = INF;
    c[++k] = N;
    k = 1;
    bellman ();
    for (int i = 2; i <= N; ++i)
        fout << cost[i] << "\n";
    fin.close (); fout.close ();
    return 0;
}