Pagini recente » Cod sursa (job #2293538) | Cod sursa (job #180040) | Cod sursa (job #1389298) | Cod sursa (job #1149917) | Cod sursa (job #2143716)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ubuntzei.in");
ofstream out("ubuntzei.out");
const int NMAX = 2000;
const int KMAX = 15;
const int INF = (1 << 30);
int d[NMAX+5][(1 << KMAX)];
bool viz[NMAX+2][(1 << KMAX)];
int spec[NMAX+5];
struct stare
{
int nod,con;
bool operator < (const stare& o) const {
return d[nod][con] > d[o.nod][o.con];
}
};
vector<pair<int,int>> G[NMAX+2];
void dijkstra()
{
priority_queue<stare> Q;
d[1][0] = 0;
Q.push({1, 0});
while( !Q.empty() ) {
int nod = Q.top().nod;
int cf = Q.top().con;
Q.pop();
if( viz[nod][cf] ) continue;
viz[nod][cf] = 1;
for( auto& pp : G[nod] ) {
int x = pp.first;
int ncost = d[nod][cf] + pp.second;
int mk = cf | spec[x];
if( !viz[x][mk] && ncost < d[x][mk] ) {
d[x][mk] = ncost;
Q.push({x, mk});
}
}
}
}
int main()
{
int N, M, K;
in >> N >> M >> K;
for( int i = 0; i < K; ++i ) {
int x;
in >> x;
spec[x] = (1 << i);
}
for( int i = 1; i <= M; ++i ) {
int x,y,c;
in >> x >> y >> c;
G[x].push_back({y,c});
G[y].push_back({x,c});
}
for( int i = 1; i <= N; ++i ) for( int j = 0; j < (1 << K); ++j )
d[i][j] = INF;
dijkstra();
out << d[N][(1 << K) - 1] << '\n';
return 0;
}