Pagini recente » Cod sursa (job #1640446) | Cod sursa (job #2792764) | Cod sursa (job #463758) | Cod sursa (job #2208001) | Cod sursa (job #2037299)
#include <fstream>
#include <queue>
#include <cstring>
#include <vector>
#define inf 0x3f3f3f3f
#define MAXN 2002
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
int n, m, k, x, prieten[MAXN];
int sol[MAXN][MAXN], z, aux, nr_p;
struct two{
int nod, c;
};
struct str{
int node, pr, cost;
bool operator < (const str& other) const{
return cost > other.cost;
}
};
vector <two> G[MAXN];
priority_queue <str> Q;
inline void Read() {
int y, z;
fin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
fin >> x;
prieten[x] = 1;
}
for (int i = 1; i <= m; i++) {
fin >> x >> y >> z;
G[x].push_back({y, z});
G[y].push_back({x, z});
}
}
inline void Init() {
memset(sol, inf, sizeof(sol));
}
inline int Dijkstra(int start) {
sol[start][0] = 0;
Q.push({start, 0, 0});
while (!Q.empty()) {
z = Q.top().node;
aux = Q.top().pr;
for (auto x: G[z]) {
nr_p = aux;
if (prieten[x.nod] == 1) {
nr_p++;
}
if (sol[x.nod][nr_p] > sol[z][aux] + x.c) {
sol[x.nod][nr_p] = sol[z][aux] + x.c;
Q.push({x.nod, nr_p, sol[x.nod][nr_p]});
}
}
Q.pop();
}
return sol[n][k];
}
int main () {
Read();
Init();
fout << Dijkstra(1);
fin.close(); fout.close(); return 0;
}