Pagini recente » Cod sursa (job #1239774) | Cod sursa (job #1518371) | Cod sursa (job #3136420) | Cod sursa (job #430444) | Cod sursa (job #2100908)
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream fin ("ubuntzei.in");
ofstream fout ("ubuntzei.out");
const int NMAX = 2000 + 5;
const int MMAX = 10000 + 5;
const int oo = 1 << 30;
int N, M, K, c[NMAX];
int dp[NMAX][NMAX];
struct Elem
{
int nod;
int cost;
bool operator<(const Elem &arg)const
{
return cost > arg.cost;
}
Elem (int _nod = 0, int _cost = 0)
{
nod = _nod;
cost = _cost;
}
};
priority_queue <Elem> q;
vector < Elem > gr[NMAX];
void read()
{
int x, y, z;
fin >> N >> M;
fin >> K;
for (int i = 1; i <= K; ++i)
fin >> c[i];
Elem aux;
for(int i = 1; i <= M; ++i)
{
fin >> x >> y >> z;
aux.nod = y;
aux.cost = z;
gr[x].push_back(aux);
aux.nod= x;
gr[y].push_back(aux);
}
}
int Dijkstra(int poz, int co)
{
Elem aux, alt;
for (int i=1;i<=N;i++) dp[poz][i]=oo;
dp[poz][co] = 0;
alt.nod = co;
alt.cost = 0;
q.push(Elem(poz, co));
while (!q.empty())
{
alt = q.top();
q.pop();
if (alt.cost == dp[poz][alt.nod])
{
for (vector <Elem> ::iterator it=gr[alt.nod].begin();it!=gr[alt.nod].end();it++)
{
aux = *it;
if (dp[poz][aux.nod] > dp[poz][alt.nod] + aux.cost)
{
dp[poz][aux.nod] = dp[poz][alt.nod] + aux.cost;
aux.cost = dp[poz][aux.nod];
q.push(Elem(aux.nod, aux.cost));
}
}
}
}
}
int main()
{
read();
Dijkstra(0, 1);
//for (int i = 1; i <= K; ++i) Dijkstra(i, c[i]);
if (K == 0) fout << dp[0][N];
return 0;
}