Pagini recente » Cod sursa (job #2957134) | Cod sursa (job #278105) | Cod sursa (job #347702) | Cod sursa (job #2271980) | Cod sursa (job #2654349)
#include <fstream>
#include<deque>
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
struct dr{int oras;int cost;};
int n,k,m,ubuntz[2001][1<<17],dorm[2001];
deque<dr>drum[10001];
void parcurgere(int oras,int omuleti)
{
for(int i=1;i<=drum[oras].size();i++)
{
dr nou=drum[oras].front();drum[oras].push_back(drum[oras].front());drum[oras].pop_front();
int nou_oras=nou.oras;int nou_cost=nou.cost;
if(dorm[nou_oras]!=0&&((omuleti&(1<<dorm[nou_oras]))==0))
{
if((ubuntz[nou_oras][omuleti+(1<<dorm[nou_oras])]>ubuntz[oras][omuleti]+nou_cost+(ubuntz[oras][omuleti]==-1?1:0))||ubuntz[nou_oras][omuleti+(1<<dorm[nou_oras])]==0)
{
ubuntz[nou_oras][omuleti+(1<<dorm[nou_oras])]=ubuntz[oras][omuleti]+nou_cost+(ubuntz[oras][omuleti]==-1?1:0);
parcurgere(nou_oras,omuleti+(1<<dorm[nou_oras]));
}
}
else
if((ubuntz[nou_oras][omuleti]>ubuntz[oras][omuleti]+nou_cost+(ubuntz[oras][omuleti]==-1?1:0))||ubuntz[nou_oras][omuleti]==0)
{
ubuntz[nou_oras][omuleti]=ubuntz[oras][omuleti]+nou_cost+(ubuntz[oras][omuleti]==-1?1:0);
parcurgere(nou_oras,omuleti);
}
}
}
int main()
{ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
f>>n>>m>>k;
for(int i=1;i<k+1;i++)
{
int yy;
f>>yy;
dorm[yy]=i;
}
for(int i=1;i<=m;i++)
{int x,y,cost;
f>>x>>y>>cost;
dr pus;pus.oras=y;pus.cost=cost;
drum[x].push_front(pus);
pus.oras=x;
drum[y].push_front(pus);
}
ubuntz[1][0]=-1;
parcurgere(1,0);
int uu=1;
for(int i=1;i<=k;i++)
uu*=2;
g<<ubuntz[n][uu];
return 0;
}