#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
constexpr double inf = 1e18;
vector<vector<pair<int, int>>> g;
vector<double> get(int t, int n, int skip) {
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
vector<double> d(n, inf);
d[t] = 0;
pq.push({0, t});
while (!pq.empty()) {
auto [k, u] = pq.top();
pq.pop();
if (k > d[u]) continue;
for (auto [v, w] : g[u]) {
if (v == skip) continue;
if (d[v] > k + w) {
d[v] = k + w;
pq.push({d[v], v});
}
}
}
return d;
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
g.assign(n, {});
for (int i = 0; i < m; i++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
vector<vector<double>> dp(n, vector<double>(k + 1, inf));
fill(dp[0].begin(), dp[0].end(), 0);
for (int i = 0; i < h; i++) {
assert(x[i] == i);
assert(y[i] == i + 1);
// i, i + 1, c[i]
for (int j = 0; j <= k; j++) {
dp[i + 1][j] = dp[i][j] + c[i];
}
if (arr[i + 1] == 0) {
ranges::fill(dp[i + 1], 0);
continue;
}
if (arr[i + 1] == 2) {
for (int j = 0; j < k; j++) {
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], (dp[i][j] + c[i]) / 2);
}
}
if (arr[i + 1] == 2 && arr[i] == 2) {
for (int j = 0; j < k; j++) {
for (int s = 2; j + s <= k; s += 2) {
double x = dp[i][j];
for (int _ = 0; _ < s; _++) {
x += c[i];
x /= 2;
}
dp[i + 1][j + s] = min(dp[i + 1][j + s], x);
}
}
}
}
return dp[h][k];
}