Pagini recente » Cod sursa (job #1361605) | Cod sursa (job #600059) | Cod sursa (job #699774) | Cod sursa (job #1407132) | Cod sursa (job #1374523)
#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;
}