Pagini recente » Cod sursa (job #691264) | Cod sursa (job #1122024) | Cod sursa (job #781333) | Cod sursa (job #1022845) | Cod sursa (job #1024427)
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
using namespace std;
ifstream cin("retea.in");
ofstream cout("retea.out");
const double eps = 1e-5;
const int NMAX = 1001;
int N, M, K;
double dist[1<<14];
double edge[int(1e5)];
vector<int> G[NMAX];
priority_queue< pair< double ,int> > Q;
inline bool comp(const double &a,const double b) {
return a - b > eps;
}
inline void readData() {
cin>>N>>M>>K;
for(int a, b, c, e = 0;e < M;e++) {
cin>>a>>b>>c;
G[a].push_back(b + (e<<10));
G[b].push_back(a + (e<<10));
edge[e] = 1.0*c/(1<<K);
}
}
inline void djikstra() {
for(int i = 1;i <= N;i++) {
for(int j = 0;j <= K;j++) {
dist[i | j<<10] = int(2e9)*1.0;
}
}
dist[1] = 0;
Q.push(mp(0,1));
double c;
int ww, e;
while(!Q.empty()) {
int V = Q.top().y;
int v = V & 1023, k = V>>10;
if (v == K && k == K) break;
Q.pop();
for(const int &w : G[v]) {
ww = w & 1023;
e = w>>10;
c = 1ll*edge[e]*(1ll<<k);
for(int j = K;j >= k;j--, c *= 2.0) {
if(comp(dist[ww | j<<10] ,dist[V] + c)) {
dist[ww | j<<10] = dist[V] + c;
Q.push(mp(-dist[ww | j<<10],ww | j<<10));
}
}
}
}
}
int main()
{
readData();
djikstra();
cout.precision(4);
cout<<fixed<<1.0*dist[N | K<<10];
return 0;
}