#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
const long long maxn = 1e3;
long long ci[1010];
long long dis[1010];
long long val[1010];
bool mark[1010];
long long dist[1010][1010];
vector<pair<long long, long long> > a[1010];
vector<pair<long long, long long> > help[1010];
set<pair<long long, long long> > s;
int main() {
  long long n, m, r, g;
  cin >> n >> m >> r >> g;
  r--, g--;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    a[u].push_back(make_pair(v, w));
    a[v].push_back(make_pair(u, w));
  }
  for (long long i = 0; i < n; i++) {
    cin >> dis[i] >> ci[i];
  }
  for (long long k = 0; k < n; k++) {
    val[k] = 0;
    s.insert(make_pair(0, k));
    for (long long i = 0; i < n; i++) {
      if (i != k) {
        val[i] = inf;
        s.insert(make_pair(inf, i));
      }
    }
    for (long long i = 0; i < n; i++) {
      pair<long long, long long> t = *s.begin();
      long long x = t.second;
      long long valt = t.first;
      for (long long j = 0; j < a[x].size(); j++) {
        if (valt + a[x][j].second < val[a[x][j].first]) {
          s.erase(make_pair(val[a[x][j].first], a[x][j].first));
          s.insert(make_pair(valt + a[x][j].second, a[x][j].first));
          val[a[x][j].first] = valt + a[x][j].second;
        }
      }
      s.erase(t);
    }
    for (long long i = 0; i < n; i++) {
      dist[k][i] = val[i];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i != j) {
        if (dist[i][j] <= dis[i]) {
          help[i].push_back(make_pair(j, ci[i]));
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    val[i] = inf;
  }
  val[r] = 0;
  for (long long i = 0; i < n; i++) {
    long long max = inf;
    long long x;
    for (long long j = 0; j < n; j++) {
      if (val[j] < max && !mark[j]) {
        max = val[j];
        x = j;
      }
    }
    mark[x] = 1;
    for (long long j = 0; j < help[x].size(); j++) {
      if (val[help[x][j].first] > val[x] + help[x][j].second) {
        val[help[x][j].first] = val[x] + help[x][j].second;
      }
    }
  }
  if (val[g] >= inf) {
    cout << -1;
  } else {
    cout << val[g];
  }
  return 0;
}
