Cod sursa(job #1374523)

Utilizator Pintilie_AndreiFII-Pintilie Andrei Pintilie_Andrei Data 5 martie 2015 09:47:20
Problema Ubuntzei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define oo 1<<30
#define N 2004
using namespace std;
struct str
{
    int x,c;
};
vector <str> a[N];
queue <int> q;
int ko[20];
int d[N][20];
int dp[1<<16][20];
int n,m,k;
void Read()
{
    ifstream fin("ubuntzei.in");
    fin>>n>>m>>k;
    int z,y,i;
    str w;
    for(i=1; i<=k; i++)
        fin>>ko[i];
    for(i=1; i<=m; i++)
    {
        fin>>w.x>>y>>w.c;
        a[y].push_back(w);
        swap(w.x,y);
        a[y].push_back(w);
    }
}

void Setoo()
{
    for(int i=1; i<=n; i++)
        for(int j=1; j<=k; j++)
        d[i][j]=oo;
}

void BellF(int j,int rad)
{
    q.push(rad);
    d[rad][j]=0;
    int nod;
    int i;
    while(!q.empty())
    {
        nod=q.front();
        q.pop();
        for(i=0; i<a[nod].size(); i++)
            if(d[a[nod][i].x][j]>d[nod][j]+a[nod][i].c)
        {
            d[a[nod][i].x][j]=d[nod][j]+a[nod][i].c;
            q.push(a[nod][i].x);
        }
    }
}
void MakeBell()
{
    for(int i=1; i<=k; i++)
        BellF(i,ko[i]);
}

void Salv()
{
    int i,j;
    for(i=1; i<=k; i++)
        for()
}
int main()
{
    Read();
    Setoo();
    MakeBell();
    for(int i=1; i<=n; i++)
        cout<<d[i][1]<<" ";
    return 0;
}