Pagini recente » Cod sursa (job #1534382) | Cod sursa (job #780822) | Monitorul de evaluare | Cod sursa (job #2592184) | Cod sursa (job #1008272)
//Solutie 20 puncte
#include <fstream>
#include <vector>
#include <queue>
#include <string.h>
#define IN "ubuntzei.in"
#define OUT "ubuntzei.out"
#define MAX_SIZE 2009
#define oo 1000000
std :: ifstream f(IN);
std :: ofstream g(OUT);
int N, M, K;
int VIZ[MAX_SIZE], BestD[MAX_SIZE];
std :: vector < std :: pair < int, int > > V[MAX_SIZE];
std :: queue < int > Q;
inline void READ_DATA()
{
int a;
f >> N >> M >> K;
for(int i = 1; i <= K; ++i) f >> a;
int x, y, z;
for(int i = 1; i <= M; ++i)
{
f >> x >> y >> z;
V[x].push_back(std :: make_pair(y, z));
V[y].push_back(std :: make_pair(x, z));
}
}
void BF()
{
int nod;
std :: vector < std :: pair < int, int > > :: iterator it;
Q.push(1);
BestD[1] = 0;
while(!Q.empty())
{
nod = Q.front();
Q.pop();
for(it = V[nod].begin(); it != V[nod].end(); ++it)
if(BestD[(*it).first] > BestD[nod] + (*it).second)
{
BestD[(*it).first] = BestD[nod] + (*it).second;
Q.push((*it).first);
}
}
}
int main()
{
READ_DATA();
memset(BestD, oo, sizeof(BestD));
BF();
g << BestD[N] << '\n';
g.close();
return 0;
}