Pagini recente » Cod sursa (job #2798337) | Cod sursa (job #2834358) | Cod sursa (job #145223) | Cod sursa (job #3171758) | Cod sursa (job #890993)
Cod sursa(job #890993)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
int n,m,b[9000],k,sum;
long long int a[9999][9999];
int const MAX=999999999;
void init()
{f>>n>>m>>k;
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i==j) a[i][j]=0;
else a[i][j]=MAX;
}
void citire()
{int c,d,e;
for(int i=1;i<=k;i++)
f>>b[i];
for(int i=1;i<=m;i++)
{f>>d>>e>>c;
a[d][e]=c;a[e][d]=c;
}
}
void transf()
{for(int d=1;d<=n;d++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][d]+a[d][j]<a[i][j])
a[i][j]=a[i][d]+a[d][j];
}
void solutia()
{sort(b,b+k+1);
if(k!=0)
{sum=a[1][b[1]];
for(int i=1;i<k;i++)
sum+=a[b[i]][b[i+1]];
sum+=a[b[k]][n];
}else sum=a[1][n];
}
int main()
{
init(); citire(); transf();solutia();g<<sum;f.close();g.close();
}