Pagini recente » Cod sursa (job #1734862) | Cod sursa (job #2745767) | Cod sursa (job #700174) | Cod sursa (job #2163128) | Cod sursa (job #2566710)
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
const int MAXN = 2005, MAXK = 15, INF = 0x3f3f3f3f;
vector<pair<int, int>> graph[MAXN];
unordered_map<int, int> dp[MAXN];
int pos[MAXN], n, m, k;
queue<pair<int, int>> q;
void init()
{
for (int i = 1; i <= n; ++i)
pos[i] = -1;
}
void read()
{
fin >> n >> m >> k;
init();
for (int i = 0; i < k; ++i) {
int x;
fin >> x;
pos[x] = i;
}
for (int i = 0; i < m; ++i) {
int x, y, c;
fin >> x >> y >> c;
graph[x].pb({y, c});
graph[y].pb({x, c});
}
}
void solve()
{
q.push({1, 0});
while (!q.empty()) {
int node = q.front().first, mask = q.front().second;
q.pop();
for (const auto& it: graph[node]) {
int newM = mask;
if (pos[it.first] != -1)
newM |= (1 << pos[it.first]);
if (dp[it.first][newM] == 0 && (it.first != 1 || newM != 0))
dp[it.first][newM] = INF;
if (dp[it.first][newM] > dp[node][mask] + it.second) {
dp[it.first][newM] = dp[node][mask] + it.second;
q.push({it.first, newM});
}
}
}
}
int main()
{
read();
solve();
fout << dp[n][1 << k - 1];
return 0;
}