#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const long long INFINITE = (long long)1e15;
vector<pair<int, int> > e[MAXN];
vector<pair<int, long long> > e2[MAXN];
long long cost[MAXN][MAXN];
int n, m, x, y, u, v, w;
bool visit[MAXN];
long long d[MAXN];
void gao(int st, int le, int cs) {
  for (int i = 0; i < n; ++i) d[i] = INFINITE;
  priority_queue<pair<long long, int> > q;
  d[st] = 0;
  for (int i = 0; i < n; ++i) visit[i] = 0;
  q.push(make_pair(-d[st], st));
  while (!q.empty()) {
    u = q.top().second;
    q.pop();
    if (visit[u]) continue;
    if (d[u] > le) return;
    cost[st][u] = min(cost[st][u], (long long)cs);
    if (u != st) e2[st].push_back(make_pair(u, cost[st][u]));
    visit[u] = true;
    for (int i = 0; i < e[u].size(); i++) {
      v = e[u][i].first;
      w = e[u][i].second;
      if (d[u] + w < d[v]) {
        d[v] = d[u] + w;
        q.push(make_pair(-d[v], v));
      }
    }
  }
}
long long dijkstra(int st, int ed) {
  for (int i = 0; i < n; ++i) d[i] = INFINITE;
  priority_queue<pair<long long, int> > q;
  d[st] = 0;
  for (int i = 0; i < n; ++i) visit[i] = 0;
  q.push(make_pair(-d[st], st));
  while (!q.empty()) {
    u = q.top().second;
    q.pop();
    if (visit[u]) continue;
    if (u == ed) return d[ed];
    visit[u] = true;
    for (int i = 0; i < e2[u].size(); i++) {
      v = e2[u][i].first;
      long long w = e2[u][i].second;
      if (d[u] + w < d[v]) {
        d[v] = d[u] + w;
        q.push(make_pair(-d[v], v));
      }
    }
  }
  return -1;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &x, &y);
  --x;
  --y;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    --u;
    --v;
    e[u].push_back(make_pair(v, w));
    e[v].push_back(make_pair(u, w));
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cost[i][j] = INFINITE;
    cost[i][i] = 0;
  }
  int t, c;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &t, &c);
    gao(i, t, c);
  }
  cout << dijkstra(x, y) << endl;
  return 0;
}
