Pagini recente » Cod sursa (job #1493685) | Cod sursa (job #3268565) | Cod sursa (job #2854781) | Cod sursa (job #127105) | Cod sursa (job #2340402)
#include <fstream>
#include <queue>
#include <vector>
#include <bitset>
using namespace std;
ifstream fi("ubuntzei.in");
ofstream fo("ubuntzei.out");
const int NMAX=2005,INF=1e9;
struct oras{
int cost,conf,loc;
bool operator < (const oras &other) const
{
return cost > other.cost;
}
};
int n,m,k,p[NMAX],bst[NMAX][(1<<15)+5],x,y,cost;
bitset <(1<<15)+5> VIZ[NMAX];
priority_queue <oras> pq;
vector <pair<int,int>> V[NMAX];
void dijkstra()
{
for(int i=1;i<=n;i++)
for(int conf=0;conf<(1<<k);conf++)
bst[i][conf]=INF;
pq.push({0,0,1});
bst[1][0]=0;
while(!pq.empty())
{
oras o=pq.top();
pq.pop();
int x=o.loc;
int conf=o.conf;
if(VIZ[x][conf]) continue;
VIZ[x][conf]=1;
for(auto edge: V[x])
{
y=edge.first;
cost=edge.second;
int conf2;
if(p[y]) conf2=conf+(1<<(p[y]-1));
else conf2=conf;
if(bst[y][conf2]>bst[x][conf]+cost)
{
bst[y][conf2]=bst[x][conf]+cost;
VIZ[y][conf2]=0;
pq.push({bst[y][conf2],conf2,y});
}
}
}
}
int main()
{
fi>>n>>m>>k;
for(int i=1;i<=k;i++)
{
fi>>x;
p[x]=i;
}
for(int i=1;i<=m;i++)
{
fi>>x>>y>>cost;
V[x].push_back({y,cost});
V[y].push_back({x,cost});
}
dijkstra();
fo<<bst[n][(1<<k)-1]<<"\n";
fi.close();
fo.close();
return 0;
}