#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, m, dis[55][55], fast[55], slow[55], g1, g2, s1, s2;
long long f[55][55][55];
bool cang[55], cans[55], canb[55];
long long work(int g, int b, int su, int sd) {
  memset(f, 0, sizeof(f));
  memset(cang, false, sizeof(cang));
  memset(cans, false, sizeof(cans));
  memset(canb, false, sizeof(canb));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) {
        continue;
      }
      if (dis[i][j] <= g) {
        cang[i] = true;
      }
      if (dis[i][j] > su && dis[i][j] < sd) {
        cans[i] = true;
      }
      if (dis[i][j] >= b) {
        canb[i] = true;
      }
    }
  }
  f[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; j + k <= i; k++) {
        if (cang[i]) {
          f[i][j + 1][k] += f[i - 1][j][k];
        }
        if (cans[i]) {
          f[i][j][k + 1] += f[i - 1][j][k];
        }
        if (canb[i]) {
          f[i][j][k] += f[i - 1][j][k];
        }
      }
    }
  }
  long long res = 0;
  for (int i = g1; i <= g2; i++) {
    for (int j = s1; j <= s2; j++) {
      res += f[n][i][j];
    }
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dis[i][j] = dis[j][i] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    dis[x][y] = dis[y][x] = w;
  }
  scanf("%d%d%d%d", &g1, &g2, &s1, &s2);
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dis[i][j] < inf) {
        dis[i][j] = dis[i][j] * n + i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    fast[i] = inf;
    slow[i] = -inf;
    for (int j = 1; j <= n; j++) {
      if (i == j) {
        continue;
      }
      fast[i] = min(fast[i], dis[i][j]);
      slow[i] = max(slow[i], dis[i][j]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans += work(fast[i], slow[j], fast[i], slow[j]) -
             work(fast[i] - 1, slow[j], fast[i], slow[j]) -
             work(fast[i], slow[j] + 1, fast[i], slow[j]) +
             work(fast[i] - 1, slow[j] + 1, fast[i], slow[j]);
    }
  }
  cout << ans << endl;
  return 0;
}
