#include <bits/stdc++.h>
std::vector<int> vizitat;
std::vector<std::vector<std::pair<int,int>>> graf;
std::queue<int> q; std::vector<int> cost;
void bfs(int n) {
q.push(n);
vizitat[n] = 1; cost[n] = 0;
while (!q.empty()) {
int nod = q.front(); q.pop();
for (auto [a, b] : graf[nod]) {
if (!vizitat[a]) {
vizitat[a] = 1;
cost[a] = cost[nod] + b;
q.push(a);
}
}
}
}
int main(){
int n, m, x, y;
std::ifstream fin("sate.in");
std::ofstream fout("sate.out");
fin >> n >> m >> x >> y;
for (int i = 0; i < m; i++) {
int a, b, c;
fin >> a >> b >> c;
graf[a].push_back({b, c});
graf[b].push_back({a, c});
}
graf.resize(n + 1);
vizitat.assign(n + 1, false);
cost.assign(n + 1, 0);
bfs(x);
fout << std::abs(cost[y]);
}