Pagini recente » Cod sursa (job #1358420) | Cod sursa (job #1860563) | Cod sursa (job #609428) | Cod sursa (job #1068799) | Cod sursa (job #2654197)
#include <fstream>
#include<deque>
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
struct dr{int oras;int cost;};
struct pt_coada{int oras;int ubun;};
int ubuntz[20][655],n,m,k,dorm[2001],wer[2001][16][16];
deque<pt_coada>q;
deque<dr>drum[10001];
int main()
{ifstream f("ubuntzei.in");
ofstream g("ubuntzei.out");
f>>n>>m>>k;
for(int i=1;i<=m;i++)dorm[i]=0;
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);
}
int yyy=pow(2,k)-1;
bool aa=4&2;
for(int j=1;j<=n;j++)
for(int i=0;i<=yyy;i++)
ubuntz[j][i]=INT_MAX;
ubuntz[1][0]=0;
pt_coada nou;nou.oras=1;nou.ubun=0;
q.push_front(nou);
while(!q.empty())
{
pt_coada scos=q.front();q.pop_front();
int oras=scos.oras;
int omuleti=scos.ubun;
for(int i=1;i<=drum[oras].size();i++)
{
dr nou_chestie=drum[oras].front();
drum[oras].push_back(drum[oras].front());
drum[oras].pop_front();
int nou_oras=nou_chestie.oras;
int nou_cost=nou_chestie.cost;
if(dorm[nou_oras]!=0)
{int yui=(omuleti)+(1<<(dorm[nou_oras]-1));
if(((omuleti&(1<<(dorm[nou_oras]-1)))==0)&&ubuntz[oras][omuleti]+nou_cost<ubuntz[nou_oras][yui])
{
ubuntz[nou_oras][yui]=ubuntz[oras][omuleti]+nou_cost;
q.push_back({nou_oras,yui});
}
else
if(ubuntz[oras][omuleti]+nou_cost<ubuntz[nou_oras][omuleti])
{
ubuntz[nou_oras][omuleti]=ubuntz[oras][omuleti]+nou_cost;
q.push_back({nou_oras,omuleti});
}
}
else
{
if(ubuntz[oras][omuleti]+nou_cost<ubuntz[nou_oras][omuleti])
{
ubuntz[nou_oras][omuleti]=ubuntz[oras][omuleti]+nou_cost;
q.push_back({nou_oras,omuleti});
}
}
}
}
int uu=1;
for(int i=1;i<=k;i++)
uu*=2;
uu--;
g<<ubuntz[n][uu];
return 0;
}