Cod sursa(job #2653765)

Utilizator serbanmihaiserban ionescu mihai serbanmihai Data 29 septembrie 2020 01:06:09
Problema Ubuntzei Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <fstream>
#include<deque>
using namespace std;
struct dr{int oras;int cost;};
struct pt_coada{int oras;int ubun;};
int ubuntz[2001][16],n,m,k,dorm[2001];
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;i++)
    {
        int yy;
        f>>yy;
        dorm[yy]=1;
    }
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);
}
for(int j=1;j<=m;j++)
for(int i=0;i<=k;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 de_pus=drum[oras].front();
        if(dorm[de_pus.oras]==1)
        if(ubuntz[oras][omuleti]+de_pus.cost<ubuntz[de_pus.oras][omuleti+1])
        {
            ubuntz[de_pus.oras][omuleti+1]=ubuntz[oras][omuleti]+de_pus.cost;
            pt_coada yy;yy.oras=de_pus.oras;yy.ubun=omuleti+1;
            q.push_back(yy);
        }
        if(dorm[de_pus.oras]==0)
        if(ubuntz[oras][omuleti]+de_pus.cost<ubuntz[de_pus.oras][omuleti])
        {
            ubuntz[de_pus.oras][omuleti]=ubuntz[oras][omuleti]+de_pus.cost;
            pt_coada yy;yy.oras=de_pus.oras;yy.ubun=omuleti;
            q.push_back(yy);
        }
        drum[oras].push_back(drum[oras].front());
        drum[oras].pop_front();
    }

}
g<<ubuntz[n][k];


    return 0;
}