#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
constexpr long long inf = 1e18;
vector<vector<pair<int, int>>> g;
vector<long long> get(int t, int n) {
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
vector<long long> 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 (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<long long> d = get(h, n);
double ans = d[0];
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
ans = min(ans, (double)d[i]);
}
}
return ans;
}