Pagini recente » Cod sursa (job #368750) | Cod sursa (job #2460923) | Cod sursa (job #1853813) | Cod sursa (job #2579180) | Cod sursa (job #2321461)
#include <bits/stdc++.h>
#define piii pair<pair<int,short>,short>
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
vector<pair<short,int> >nod[2005];
int n,m,k,x,y,c;
short pretin[20];
short val[2005];
int dp[2005][32800];
priority_queue<piii,vector<piii >,greater<piii > >pq;
int main()
{
fin>>n>>m>>k;
memset(val,-1,sizeof val);
for(int i=0;i<k;i++)
{
fin>>pretin[i];
val[pretin[i]]=i;
}
for(int i=1;i<=m;i++)
{
fin>>x>>y>>c;
nod[x].push_back({y,c});
nod[y].push_back({x,c});
}
pq.push({{0,0},1});
while(!pq.empty())
{
int cst=pq.top().first.first;
short v=-pq.top().first.second;
short pos=pq.top().second;
pq.pop();
if(dp[pos][v]!=0 && dp[pos][v]<cst) continue;
dp[pos][v]=cst;
for(int i=0;i<nod[pos].size();i++)
{
int counter=v;
if(val[nod[pos][i].first]!=-1)
{
if((counter&(1<<val[nod[pos][i].first]))!=0) continue;
counter+=(1<<val[nod[pos][i].first]);
}
if(dp[nod[pos][i].first][counter]!=0 && dp[nod[pos][i].first][counter]<=cst+nod[pos][i].second) continue;
pq.push({{nod[pos][i].second+cst,-counter},nod[pos][i].first});
}
}
fout<<dp[n][(1<<k)-1];
return 0;
}