Pagini recente » Cod sursa (job #2747849) | Cod sursa (job #141008) | Cod sursa (job #1168955) | Cod sursa (job #2115376) | Cod sursa (job #2542044)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ofstream g("ubuntzei.out");
const int NMAX = 2005;
const int oo = (1 << 30);
int D[NMAX], N, M, K;
int Friends[NMAX];
bool InCoada[NMAX];
struct Compara{
bool operator()(int x,int y){
return D[x]>D[y];
}
};
vector < pair < int, int > > G[NMAX];
priority_queue < int, vector < int > , Compara > Coada;
void Read(){
ifstream f("ubuntzei.in");
f >> N >> M >> K;
for(int i = 1; i <= K;i++)
f >> Friends[i];
for(int i = 1; i <= M;i++){
int x,y,c;
f >> x >> y >> c;
G[x].push_back(make_pair(y,c));
G[y].push_back(make_pair(x,c));
}
}
void Dijkstra(int Nod){
for(int i = 1; i <= N;i++)
D[i] = oo;
D[Nod] = 0;
Coada.push(Nod);
InCoada[Nod] = true;
while(!Coada.empty()){
int nodCurent = Coada.top();
Coada.pop();
InCoada[Nod] = false;
for(unsigned int i = 0; i < G[nodCurent].size();i++){
int Vecin = G[nodCurent][i].first;
int Cost = G[nodCurent][i].second;
if(D[Vecin] > D[nodCurent]+ Cost){
D[Vecin] = D[nodCurent] + Cost;
if(!InCoada[Vecin]){
InCoada[Vecin] = true;
Coada.push(Vecin);
}
}
}
}
}
int main()
{
Read();
Dijkstra(1);
g << D[N];
return 0;
}