Pagini recente » Cod sursa (job #1326372) | Cod sursa (job #2480714) | Cod sursa (job #2079279) | Rating Iovan Ecaterina-Claudia (iclaudya89) | Cod sursa (job #2037289)
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#define MAXN 2002
#define inf 0x3f3f3f3f
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
int n, k, nr_p, aux, z, prieten[MAXN], m, sol[MAXN][25];
struct str{
int node, pr, c;
bool operator < (const str& other) const {
if (c == other.c)
return pr < other.pr;
return c > other.c;
}
};
struct two{
int nod, cost;
};
vector <two> G[MAXN];
priority_queue <str> Q;
inline void Read() {
int x, y;
fin >> n >> m;
fin >> 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 = nr_p = Q.top().pr;
for (auto x : G[z]) {
if (prieten[x.nod] == 1)
nr_p = aux + 1;
else
nr_p = aux;
if (sol[x.nod][nr_p] > sol[z][aux] + x.cost) {
sol[x.nod][nr_p] = sol[z][aux] + x.cost;
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;
}