Pagini recente » Cod sursa (job #2444272) | Cod sursa (job #2772385) | Cod sursa (job #2792312) | Cod sursa (job #257358) | Cod sursa (job #1865252)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define MAXX 200000
using namespace std;
ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
vector <pair<int, int> > G[2010];
priority_queue <pair<int, int> > PQ;
int n,m,d[2010],viz[2010],orase[2010],x;
void Dijkstra(int x)
{
for(int i=1;i<=n;i++)
d[i]=MAXX;
d[x]=0;
viz[x]=1;
{
int nod=x;
int nr=G[nod].size();
for(int i=0;i<nr;i++)
{
d[G[nod][i].first]=G[nod][i].second;
PQ.push(make_pair(-d[G[nod][i].first],G[nod][i].first));
}
}
while(PQ.size())
{
pair <int,int> val=PQ.top();
PQ.pop();
int nod=val.second;
if(viz[nod]==0)
{
viz[nod]=1;
int nr=G[nod].size();
for(int i=0;i<nr;i++)
if(viz[G[nod][i].first]==0 && d[G[nod][i].first]>d[nod]+G[nod][i].second)
{
d[G[nod][i].first]=d[nod]+G[nod][i].second;
PQ.push(make_pair(-d[G[nod][i].first],G[nod][i].first));
}
}
}
g<<d[n];
}
int main()
{
f>>n>>m>>x;
for(int i=1;i<=x;i++)
f>>orase[i];
for(int i=1;i<=m;i++)
{
int a,b,c;
f>>a>>b>>c;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
Dijkstra(1);
return 0;
}