#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 pair<ll, ll>
#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) {
arr[0] = 1;
k = 30;
vector<vector<pii>> adj(n);
for(ll 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});
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<ll> cost(n, 1e18+5);
pq.push({0, 0});
cost[0] = 0;
while(!pq.empty()){
auto [c, u] = pq.top();
pq.pop();
if(c > cost[u]){
continue;
}
for(auto [c, v]:adj[u]){
if(cost[v] <= cost[u] + c){
continue;
}
cost[v] = cost[u] + c;
pq.push({cost[v], v});
}
}
if(cost[h] == 1e18+5){
return (double)-1;
}
return (double)cost[h];
}
/*int main(){
int n, m, h;
cin>>n>>m>>h;
vector<int> x(m), y(m), c(m);
for(ll i = 0; i<m; i++){
cin>>x[i]>>y[i]>>c[i];
}
cout<<solve(n, m, 30, h, x, y, c, {1});
}*/