Pagini recente » Cod sursa (job #455321) | Cod sursa (job #379330) | Cod sursa (job #1783047) | Cod sursa (job #2156956) | Cod sursa (job #1210835)
#include <cstdio>
#include <queue>
#define Nmax 2005
#define INF 2000000000
using namespace std;
int N,K,dp[Nmax][20];
bool loc[Nmax];
struct Edge
{
int nod,cost;
};
struct el
{
int nod,nr,dp;
bool operator <(const el A) const
{
return dp>A.dp;
}
};
priority_queue <el> Q;
vector <Edge> L[Nmax];
inline void Dinamic()
{
el w,w1;
vector <Edge>::iterator it;
w.nod=1; w.nr=0; w.dp=0;
Q.push(w);
while(!Q.empty())
{
w=Q.top(); Q.pop();
if(w.nod==N && w.nr==K)
return;
for(it=L[w.nod].begin();it!=L[w.nod].end();++it)
{
w1.nod=it->nod;
w1.nr=w.nr;
if(loc[w1.nod]) ++w1.nr;
w1.dp=w.dp+it->cost;
if(w1.dp<dp[w1.nod][w1.nr])
{
dp[w1.nod][w1.nr]=w1.dp;
Q.push(w1);
}
}
}
}
int main()
{
int M,i,j,x,y,z;
Edge w;
freopen ("ubuntzei.in","r",stdin);
freopen ("ubuntzei.out","w",stdout);
scanf("%d%d%d", &N,&M,&K);
for(i=1;i<=K;++i)
{
scanf("%d", &x);
loc[x]=true;
}
while(M--)
{
scanf("%d%d%d", &x,&y,&z);
w.nod=y; w.cost=z;
L[x].push_back(w);
w.nod=x;
L[y].push_back(w);
}
for(i=1;i<=N;++i)
for(j=0;j<=K;++j)
dp[i][j]=INF;
dp[1][0]=0;
Dinamic();
printf("%d\n", dp[N][K]);
return 0;
}