Pagini recente » Cod sursa (job #485047) | Cod sursa (job #264934) | Cod sursa (job #2456276) | Cod sursa (job #3219768) | Cod sursa (job #2538869)
#include <bits/stdc++.h>
std::ifstream fin("ubuntzei.in");
std::ofstream fout("ubuntzei.out");
typedef long long ll;
typedef std::pair<ll, ll> pl;
ll n, m, k;
ll dist[2005][2005], list[2005], sol[20][100000];
bool check[2005], vis[2005], last[20][100000];
std::vector<pl> graph[2005];
struct str{
ll first, second, third;
};
struct comp{
bool operator()(str x, str y){
return x.first>y.first;
}
};
std::priority_queue<str, std::vector<str>, comp> pq;
void dijkstra(ll i);
int main()
{
fin>>n>>m>>k;
for(ll i=1; i<=k; ++i){
fin>>list[i];
check[list[i]]=true;
}
while(m--){
ll x, y, c;
fin>>x>>y>>c;
graph[x].push_back({c, y});
graph[y].push_back({c, x});
}
for(ll i=1; i<=k; ++i) dijkstra(i);
pq.push({0, 1, 1});
while(!pq.empty()){
str now=pq.top(); pq.pop();
if(last[now.third][now.second]) continue;
last[now.third][now.second]=true;
if(now.second==((1<<(l+1))-1)) {
fout<<now.first;
return 0;
}
ll cp=now.second;
for(ll i=1; i<=l; ++i){
if(!((now>>i)&1)){
str next={now.first+dist[now.third][list[]];}
}
}
}
return 0;
}
void dijkstra(ll i){
for(ll j=1; j<=n; ++j) {vis[j]=false; dist[i][j]=LLONG_MAX;}
pq.push({0, i, 0});
while(!pq.empty()){
str now=pq.top(); pq.pop();
if(vis[now.second] || check[now.second]) continue;
vis[now.second]=true;
for(auto neig:graph[now.second]){
str next={now.first+neig.first, neig.second, 0};
if(dist[i][next.second]>next.first){
dist[i][next.second]=next.first;
if(next.second==1 || next.second==n) dist[next.second][i]=next.first;
pq.push(next);
}
}
}
}