Cod sursa(job #1604163)

Utilizator alexmisto342Turdean Alexandru alexmisto342 Data 18 februarie 2016 00:07:06
Problema Ubuntzei Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <fstream>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#define x first
#define y second
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
int i,j,n,m,a,b,k,x,lx,ly,c,mini,is[2005],ul[2005];
vector <pair<int,int> > v[2005];
priority_queue <pair<int,pair<int,int> > , vector<pair<int,pair<int,int> > > , greater<pair<int,pair<int,int> > > >  q;
char f[2005][4100];
int main()
{
    fin >> n >> m >> k;
    for(i = 1; i <= k; i++)
        fin >> a,is[a] = 1 << (i - 1);
    int raspuns = (1 << k) - 1;
    memset(ul, -1, sizeof(ul));
    for(i = 1; i <= m; i++)
    {
        fin >> a >> b >> c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    q.push(make_pair(0,make_pair(1, 0)));
    while(true)
    {
        pair<int,pair<int,int> > now = q.top();
        q.pop();
        if(now.y.x == n && now.y.y == raspuns)
        {
            fout << now.x;
            return 0;
        }
        if(f[now.y.x][now.y.y/8] & (1 << (now.y.y % 8) ) )
            continue;
        f[now.y.x][now.y.y/8] |= (1 << (now.y.y % 8) );
        for(i = 0; i < v[now.y.x].size(); i++)
                q.push(make_pair(now.x + v[now.y.x][i].y,make_pair(v[now.y.x][i].x,(now.y.y | is[v[now.y.x][i].x]))));

    }

    return 0;
}