#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 5, inf = 1e9;
int n, m, dist[N][N], g1, g2, s1, s2;
long long dp[N][N][N], ans;
bool ok[N][3];
vector<int> vec[N];
inline void build(pair<int, int> x, pair<int, int> y) {
  memset(ok, false, sizeof ok);
  for (int i = 0; i < n; i++) {
    if (x.second == i) {
      ok[i][0] = true;
      continue;
    }
    if (y.second == i) {
      ok[i][2] = true;
      continue;
    }
    for (auto w : vec[i]) {
      pair<int, int> p = {w, i};
      if (p > y) ok[i][2] = true;
      if (p < x) ok[i][0] = true;
      if (p > x && p < y) ok[i][1] = true;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dist[i][j] = ((i == j) ? 0 : inf);
  for (int i = 0; i < m; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    v--, u--;
    dist[v][u] = dist[u][v] = w;
  }
  cin >> g1 >> g2 >> s1 >> s2;
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (i != j) vec[i].push_back(dist[i][j]);
    sort(vec[i].begin(), vec[i].end());
  }
  for (int A = 0; A < n; A++)
    for (int B = 0; B < n; B++) {
      pair<int, int> x = {vec[A][0], A};
      pair<int, int> y = {vec[B].back(), B};
      if (A == B) continue;
      build(x, y);
      memset(dp, 0, sizeof dp);
      dp[0][0][0] = 1;
      for (int g = 0; g <= n; g++)
        for (int s = 0; s <= n; s++)
          for (int b = 0; b <= n; b++) {
            if (g + s + b > n || g + s + b == 0) continue;
            int i = g + s + b - 1;
            if (g && ok[i][0]) dp[g][s][b] += dp[g - 1][s][b];
            if (s && ok[i][1]) dp[g][s][b] += dp[g][s - 1][b];
            if (b && ok[i][2]) dp[g][s][b] += dp[g][s][b - 1];
            if (g + s + b == n && g >= g1 && g <= g2 && s >= s1 && s <= s2)
              ans += dp[g][s][b];
          }
    }
  cout << ans << "\n";
}
