Pagini recente » Cod sursa (job #800498) | Cod sursa (job #2194812) | Cod sursa (job #452008) | Cod sursa (job #2932508) | Cod sursa (job #1890480)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define MAXX 900000000
using namespace std;
ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
struct muchie
{
int nod,dist,ubu;
bool operator<(const muchie &altu)const
{
return dist<altu.dist;
}
};
vector <muchie> G[2010];
int p[2010],n,m,k,viz[2010][2010],d[2010][2010],vizz[2010];
void Dijkstra()
{
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++)
d[i][j]=MAXX;
d[1][0]=0;
priority_queue <muchie> pq;
muchie dr;
dr.nod=1;
dr.ubu=0;
dr.dist=0;
pq.push(dr);
while(!pq.empty())
{
dr=pq.top();
pq.pop();
if(!viz[dr.nod][dr.ubu])
{
viz[dr.nod][dr.ubu]=1;
for(int i=0;i<G[dr.nod].size();i++)
{
muchie nou;
nou.nod=G[dr.nod][i].nod;
nou.dist=d[dr.nod][dr.ubu] + G[dr.nod][i].dist;
if (p[nou.nod])
if(!vizz[nou.nod])
{
nou.ubu=dr.ubu+p[nou.nod];
vizz[nou.nod]=0;
}
else;
else nou.ubu=dr.ubu;
if(!viz[nou.nod][nou.ubu] && nou.dist<d[nou.nod][nou.ubu])
{
d[nou.nod][nou.ubu]=nou.dist;
nou.dist=-nou.dist;
pq.push(nou);
}
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<=k;j++)
cout<<d[i][j]<<' ';
cout<<'\n';
}
g<<d[n][k];
}
int main()
{
f>>n>>m>>k;
for(int i=1;i<=k;i++)
{
int a;
f>>a;
p[a]=1;
}
for(int i=1;i<=m;i++)
{
int a,b,c;
f>>a>>b>>c;
muchie nou;
nou.nod=b;
nou.dist=c;
G[a].push_back(nou);
nou.nod=a;
G[b].push_back(nou);
}
Dijkstra();
f.close();
g.close();
return 0;
}