#include "cyberland.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii tuple<long double, int, int>
#define in(v) for(auto &elem:v){ cin>>elem; }
#define out(v) for(auto elem:v){ cout<<elem<<" "; } cout<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef tree<pii, null_type, std::greater<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> cc, vector<int> arr) {
k = min(k, 70);
vector<vector<pair<int, int>>> adj(n);
for(int i = 0; i<m; i++){
int u = x[i], v = y[i], c = cc[i];
adj[u].pb({c, v});
adj[v].pb({c, u});
}
const ll inf = 4e18;
//out(vis)
priority_queue<pii, vector<pii>, greater<pii>> pq;
double dist[n][k+1];
for(int i = 0; i<n; i++){
for(int op = 0; op<=k; op++){
dist[i][op] = inf;
}
}
pq.push({0, 0, 0});
dist[0][0] = 0;
bool vis0[n][k+1];
memset(vis0, 0, sizeof(vis0));
while(!pq.empty()){
auto [c, u, op] = pq.top();
pq.pop();
if(arr[u] == 0){
if(vis0[u][op]){
continue;
}
vis0[u][op] = 1;
}
if(c > dist[u][op]){
continue;
}
if(u == h) continue;
for(auto [c, v] : adj[u]){
double ch1 = dist[u][op] + c;
if(arr[v] == 0) ch1 = 0;
if(dist[v][op] > ch1){
dist[v][op] = ch1;
pq.push({ch1, v, op});
}
if(op < k && arr[u] == 2){
double ch2 = dist[u][op] / 2 + c;
if(arr[v] == 0) ch2 = 0;
if(dist[v][op + 1] > ch2){
dist[v][op + 1] = ch2;
pq.push({ch2, v, op + 1});
}
}
}
}
//out(dist);
double ans = inf;
for(int i = 0; i<=k; i++){
if(dist[h][i] <= ans){
ans = dist[h][i];
}
}
if(ans >= 3e18){
return -1;
}
return ans;
}
/*int main(){
int n, m, k, h;
cin>>n>>m>>k>>h;
vector<int> x(m), y(m), c(m), arr(n);
for(ll i = 0; i<m; i++){
cin>>x[i]>>y[i]>>c[i];
}
for(ll i = 0; i<n; i++){
cin>>arr[i];
}
cout<<solve(n, m, k, h, x, y, c, arr);
}*/