#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = N << 1;
int n, m, s, t;
int fir[N], to[M], nxt[M], dis[M], ecnt;
void add(int u, int v, int w) {
  to[++ecnt] = v;
  dis[ecnt] = w;
  nxt[ecnt] = fir[u];
  fir[u] = ecnt;
}
struct node {
  int id;
  unsigned long long dis;
  node(int id, unsigned long long dis) : id(id), dis(dis) {}
};
bool operator<(node a, node b) { return a.dis > b.dis; }
priority_queue<node> q;
bool vis[N];
unsigned long long d[N];
int main() {
  cin >> n >> m >> s >> t;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w);
    add(v, u, w);
  }
  fill(d + 1, d + n + 1, LONG_LONG_MAX);
  q.push(node(s, 0));
  d[s] = 0;
  while (!q.empty()) {
    node h = q.top();
    q.pop();
    if (vis[h.id]) continue;
    vis[h.id] = 1;
    for (int e = fir[h.id]; e; e = nxt[e]) {
      if (!vis[to[e]] && d[to[e]] > dis[e] + h.dis) {
        d[to[e]] = dis[e] + h.dis;
        q.push(node(to[e], d[to[e]]));
      }
    }
  }
  cout << d[t] << endl;
}
