#include using namespace std; const int N = 2510; const int M = 6200 * 2 + 10; typedef pair PII; int h[N], w[M], e[M], ne[M], idx; bool st[N]; int dis[N]; void add(int a, int b, int c) { e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++; } int n, m, S, T; int dijkstra() { memset(dis, 0x3f, sizeof dis); dis[S] = 0; priority_queue, greater> q; q.push({0, S}); while (q.size()) { PII t = q.top(); q.pop(); int u = t.second; if (st[u]) continue; st[u] = true; for (int i = h[u]; ~i; i = ne[i]) { int v = e[i]; if (dis[v] > dis[u] + w[i]) { dis[v] = dis[u] + w[i]; q.push({dis[v], v}); } } } return dis[T]; } int main() { cin >> n >> m >> S >> T; memset(h, -1, sizeof h); while (m--) { int a, b, c; cin >> a >> b >> c; add(a, b, c), add(b, a, c); } printf("%d\n", dijkstra()); return 0; }