Pagini recente » Cod sursa (job #2416035) | Cod sursa (job #155561) | Cod sursa (job #2621297) | Cod sursa (job #1338403) | Cod sursa (job #2052901)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <bitset>
#define pb push_back
#define NM 2005
using namespace std;
ifstream in("ubuntei.in");
ofstream out("ubuntei.out");
///bitset<(1<<15)+5> b[NM];
struct eee
{
int nod,cost,config;
bool operator < (const eee &a) const
{
return cost>a.cost;
}
};
priority_queue<eee> q;
vector<eee> v[NM];
int n,m,dmin[NM],c[NM],k,x,y,z;
int main()
{
in>>n>>m>>k;
for(int i=0;i<k;++i)
{
in>>x;
c[x]=(1<<i);
}
for(int i=1;i<=m;++i)
{
in>>x>>y>>z;
v[x].pb({y,z,0});
v[y].pb({x,z,0});
}
q.push({1,0,0});
while(q.top().nod!=n || q.top().config!=((1<<k)-1))
{
int nod=q.top().nod,cost=q.top().cost,config=q.top().config;
q.pop();
for(auto s:v[nod])
{
///if(c[s.nod] && config!=(config|c[s.nod]) && cost+s.cost<dmin[s.nod][config|c[s.nod]])
/// dmin[s.nod][config|c[s.nod]]=s.cost+cost;
q.push({s.nod,cost+s.cost,config|c[s.nod]});
}
}
out<<q.top().cost;
return 0;
}