#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long n, m, x, y, gl;
vector<vector<long long int>> mat(1001, vector<long long int>(1001, 1e15));
vector<vector<pair<long long int, long long int>>> adj(1001);
vector<long long int> vis(1001), trd(1001), ct(1001);
vector<vector<long long int>> tnp(1001, vector<long long int>(1001, 1e15));
void dfs(long long st, long long rem) {
  for (auto &&it : adj[st]) {
    if (vis[it.first] == 0) {
      if (rem - it.second >= 0) {
        mat[gl][it.first] = ct[gl];
        vis[it.first] = 1;
        dfs(it.first, rem - it.second);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    cin >> n >> m >> x >> y;
    for (long long int i = 0; i < m; i++) {
      long long u, v, w;
      cin >> u >> v >> w;
      tnp[u][v] = min(tnp[u][v], w);
      tnp[v][u] = min(tnp[v][u], w);
    }
    for (long long int i = 1; i < n + 1; i++) {
      for (long long int j = 1; j < n + 1; j++) {
        if (i == j || tnp[i][j] == 1e15) continue;
        adj[i].push_back(make_pair(j, tnp[i][j]));
      }
    }
    for (long long int i = 1; i < n + 1; i++) {
      cin >> trd[i] >> ct[i];
    }
    for (long long int i = 1; i < n + 1; i++) {
      vis.assign(n + 1, 0);
      vis[i] = 1;
      mat[i][i] = 0;
      gl = i;
      dfs(i, trd[i]);
    }
    set<pair<long long int, long long int>> ds;
    map<long long, long long> curv;
    for (long long int i = 1; i < n + 1; i++) {
      curv[i] = 1e15;
      ds.insert(make_pair(1e15, i));
    }
    ds.erase(make_pair(1e15, x));
    curv[x] = 0;
    ds.insert(make_pair(0LL, x));
    set<long long> tk;
    while (!ds.empty()) {
      pair<long long int, long long int> ex = *ds.begin();
      ds.erase(ex);
      tk.insert(ex.second);
      curv[ex.second] = ex.first;
      for (long long int i = 1; i < n + 1; i++) {
        if (tk.find(i) == tk.end() &&
            mat[ex.second][i] + curv[ex.second] < curv[i]) {
          ds.erase(make_pair(curv[i], i));
          curv[i] = mat[ex.second][i] + curv[ex.second];
          ds.insert(make_pair(curv[i], i));
        }
      }
    }
    if (curv[y] < 1e15)
      cout << curv[y] << "\n";
    else
      cout << -1 << "\n";
  }
  return 0;
}
