Pagini recente » Cod sursa (job #789169) | Cod sursa (job #1923446) | Cod sursa (job #285453) | Cod sursa (job #60077) | Cod sursa (job #2559560)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ubuntzei.in");
ofstream out("ubuntzei.out");
int n,m,k,x,y,ok[2005],cost,d[2005][16],ok1[2005][16];
vector<pair<int,int>> v[2005];
struct lmao
{
int nod,cate,cost;
bool operator<(const lmao &aux) const
{
if(cost!=aux.cost) return cost>aux.cost;
else return cate<aux.cate;
}
};
priority_queue<lmao> q;
lmao z;
void dijkstra(int nod)
{
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++)
d[i][j]=1e9;
if(ok[1]==0) {
q.push({1,0,0});
d[1][0]=0;
}
else
{
q.push({1,1,0});
d[1][1]=0;
}
while(!q.empty())
{
z=q.top();
q.pop();
if(ok1[z.nod][z.cate]==1) continue;
ok1[z.nod][z.cate]=1;
for(auto it:v[z.nod])
{
bool bun=0;
if(ok[it.second]==1) bun=1;
if(d[it.second][z.cate+bun]>d[z.nod][z.cate]+it.first)
{
d[it.second][z.cate+bun]=d[z.nod][z.cate]+it.first;
q.push({it.second,z.cate+bun,d[it.second][z.cate+bun]});
}
}
}
}
int main()
{
in>>n>>m;
in>>k;
for(int i=1;i<=k;i++)
{
in>>x;
ok[x]=1;
}
for(int i=1;i<=m;i++)
{
in>>x>>y>>cost;
v[x].push_back({cost,y});
v[y].push_back({cost,x});
}
dijkstra(1);
//(int i=0;i<=k;i++) cout<<d[n][i]<<" ";
out<<d[n][k];
return 0;
}