Pagini recente » Cod sursa (job #1333135) | Cod sursa (job #1364745) | Cod sursa (job #2110411) | Cod sursa (job #1216527) | Cod sursa (job #2478914)
#include <bits/stdc++.h>
#define NMAX 2000
#define KMAX 66000
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
const long long INF = 200000000001;
struct Edge {
long long dest, cost;
};
struct Drum{
int bitmask;
int dest;
long long cost;
};
vector<Edge> G[NMAX + 1];
queue<Drum> q;
long long dp[KMAX][NMAX + 1];
int n, m, k, f[NMAX + 1], poz[NMAX + 1];
void Bellman() {
for( int i = 0; i <= (1<<k) - 1; i ++ )
for( int j = 1; j <= n; j ++ )
dp[i][j] = INF;
while( !q.empty() ) {
int node = q.front().dest;
long long cost = q.front().cost;
int config = q.front().bitmask;
q.pop();
if( dp[config][node] > cost ) {
dp[config][node] = cost;
for( auto it : G[node] ) {
int newconfig = config;
if( f[it.dest] == 1 )
newconfig = config || (1<<poz[it.dest]);
q.push({newconfig, it.dest, it.cost + cost});
}
}
}
}
int main() {
fin>>n>>m;
fin>>k;
for( int i = 1; i <= k; i ++ ) {
int x;
fin>>x;
f[x] = 1;
poz[x] = i;
}
for( int i = 1; i <= m; i ++ ) {
int x, y, p;
fin>>x>>y>>p;
G[x].push_back({y,p});
G[y].push_back({x,p});
}
q.push({0,1,0});
Bellman();
fout<<dp[(1<<k) - 1][n];
return 0;
}