Cod sursa(job #2654349)

Utilizator serbanmihaiserban ionescu mihai serbanmihai Data 30 septembrie 2020 16:31:20
Problema Ubuntzei Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.72 kb
#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;
}