Pagini recente » Cod sursa (job #1585100) | Cod sursa (job #1797950) | Cod sursa (job #1174827) | Cod sursa (job #1559665) | Cod sursa (job #1626997)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <time.h>
#define maxN 2016
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
vector < pair<int,int> > v[maxN];
int n,m,k,p[20],dist[maxN];
void readData()
{
int x,y,c;
fin>>n>>m>>k;
for (int i=1; i<=k; ++i) fin>>p[i];
for (int i=1; i<=m; ++i) {
fin>>x>>y>>c;
v[x].push_back(make_pair(y,c));
v[y].push_back(make_pair(x,c));
}
}
const int oo=1<<30;
int cost[maxN][maxN];
bool inQ[maxN];
void buildCost()
{
queue <int> Q;
int i,j;
for (i=1; i<=n; ++i)
{
for (j=1; j<=n; ++j) cost[i][j]=oo;
cost[i][i]=0;
Q.push(i); inQ[i]=1;
while (!Q.empty())
{
int x=Q.front();
Q.pop(); inQ[x]=0;
for (int it=0; it<v[x].size(); ++it)
{
int w=v[x][it].first;
int c=v[x][it].second;
if (cost[i][w]>cost[i][x]+c)
{
cost[i][w]=cost[i][x]+c;
if(!inQ[w])
{
inQ[w]=1;
Q.push(w);
}
}
}
}
}
//for (i=1; i<=n; ++i){for (j=1; j<=n; ++j)cout<<cost[i][j]<<' ';cout<<'\n';}
}
int main()
{
readData();
buildCost();
if (!k) fout<<cost[1][n];
else if (k==1) fout<<cost[1][p[1]]+cost[p[1]][n];
else {
srand(time(NULL));
int Hope = rand() % 1<<30 + 1;
fout<<Hope;
}
return 0;
}