Pagini recente » Cod sursa (job #59398) | Cod sursa (job #2910911) | Cod sursa (job #1932121) | Cod sursa (job #541704) | Cod sursa (job #2230270)
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
#define lim 2000
#define oo 0x3f3f3f3f
#define mp make_pair
using namespace std;
ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
int n, m, Ref = 0, Dist[lim+1][1<<16], sv = 0;
vector<pair<int,int> > G[lim+1];
queue<pair<int,int> > Q;
bool pas[lim+1];
void Read()
{
f >> n >> m;
int k; f >> k;
for(int i = 1; i <= k; ++i)
{
int t;
f >> t;
pas[t] = 1;
Ref |= 1 << t;
}
for(int i = 1; i <= m; ++i)
{
int x, y, c;
f >> x >> y >> c;
G[x].push_back(mp(y, c));
G[y].push_back(mp(x, c));
}
}
void BelFord()
{
Q.push(mp(1, 0));
while(!Q.empty())
{
int v = Q.front().first, s = Q.front().second;
Q.pop();
for(vector<pair<int,int> > :: iterator it = G[v].begin(); it != G[v].end(); ++it)
{
int v2 = it->first, d = it->second, nexts = s;
if(pas[v2] && ((s & (1 << nexts)) == 0)) nexts |= 1 << v2;
if(Dist[v2][nexts] == 0 || Dist[v2][nexts] > Dist[v][s] + d)
{
Dist[v2][nexts] = Dist[v][s] + d;
Q.push(mp(v2, nexts));
sv = max (sv, nexts);
}
}
}
g << Dist[n][sv];
}
int main()
{
Read();
BelFord();
}