Pagini recente » Cod sursa (job #2218754) | Cod sursa (job #2158994) | Cod sursa (job #2882401) | Cod sursa (job #1488057) | Cod sursa (job #1918037)
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
struct l{int d; int par;};
struct muchie{int f; int p;};
l ml[32679][2000];
int n,nea,v[16],m;
deque<muchie> pond[2001];
int b;
int pon,ep,ev;
deque<int>q;
void citire()
{
int x,a,b,c;
muchie M,M2;
FILE*f=fopen("ubuntzei.in","r");
fscanf(f,"%i %i %i",&n,&m,&nea);
for(x=1;x<=nea;x++)
fscanf(f,"%i",&v[x]);
for(x=0;x<m;x++)
{
fscanf(f,"%i %i %i",&a,&b,&c);
a--;
b--;
M.f=b;
M.p=c;
pond[a].push_front(M);
M2.f=a;
M2.p=M.p;
pond[b].push_front(M2);
}
for(int i=0;i<=32678;i++)
{
for(int x=0;x<2000;x++)
{
ml[i][x].par=i;
ml[i][x].d=1e9;
}
}
ml[0][0].d=0;
}
void procedura();
void lpg()
{
q.push_back(0);
while(!q.empty())
{
ep=q.front();
for(deque<muchie>::iterator it=pond[ep].begin();it!=pond[ep].end();it++)
{
ev=(*it).f;
pon=(*it).p;
procedura();
}
q.pop_front();
}
}
void procedura()
{
//ep=0
//ev=2
//pon=1
bool important;
int dist;
//printf("%i %i\n",ml[0][ep].d,ml[1][ep].d);
for(int i=0;i<=32678;i++)
if(ml[i][ep].d!=1e9)
{
important=false;
for(b=1;b<=nea;b++)
if(v[b]==ev+1)
{
important=true;
break;
}
dist=ml[i][ep].d+pon;
if(important)
{
if(dist<ml[i|(1<<(b-1))][ev].d)
{
ml[i|(1<<(b-1))][ev].d=dist;
q.push_back(ev);
}
}
else
if(dist<ml[i][ev].d)
{
ml[i][ev].d=dist;
q.push_back(ev);
}
}
}
int main()
{
citire();
lpg();
// for(int x=0;x<n;x++)
// printf("%i ",ml[0][x]);
// printf("\n");
// for(int x=0;x<n;x++)
// printf("%i ",ml[1][x]);
FILE*g=fopen("ubuntzei.out","w");
fprintf(g,"%i",ml[(1<<nea)-1][n-1].d);
return 0;
}