#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int a[55], b[55], gold[55], silver[55], bronze[55], d[55][55];
long long f[55][55];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) d[i][j] = i == j ? 0 : inf;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w), u--, v--;
    if (w < d[u][v]) d[u][v] = d[v][u] = w;
  }
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  for (int i = 0; i < n; i++) {
    a[i] = inf, b[i] = -inf;
    for (int j = 0; j < n; j++)
      if (i != j) {
        d[i][j] = d[i][j] * 100 + i;
        a[i] = min(a[i], d[i][j]);
        b[i] = max(b[i], d[i][j]);
      }
  }
  int g1, g2, s1, s2;
  scanf("%d%d%d%d", &g1, &g2, &s1, &s2);
  long long res = 0;
  for (int x = 0; x < n; x++)
    for (int y = 0; y < n; y++) {
      if (x == y || a[x] >= b[y]) continue;
      for (int i = 0; i < n; i++) {
        gold[i] = a[i] <= a[x];
        bronze[i] = b[i] >= b[y];
        silver[i] = 0;
        for (int j = 0; j < n; j++)
          if (i != j && d[i][j] > a[x] && d[i][j] < b[y]) {
            silver[i] = 1;
            break;
          }
      }
      bronze[x] = silver[x] = 0;
      gold[y] = silver[y] = 0;
      memset(f, 0, sizeof(f));
      f[0][0] = 1;
      for (int k = 0; k < n; k++)
        for (int i = k; i >= 0; i--)
          for (int j = k - i; j >= 0; j--)
            if (f[i][j]) {
              if (gold[k]) f[i + 1][j] += f[i][j];
              if (silver[k]) f[i][j + 1] += f[i][j];
              if (!bronze[k]) f[i][j] = 0;
            }
      for (int i = g1; i <= g2; i++)
        for (int j = s1; j <= s2; j++) res += f[i][j];
    }
  printf("%I64d\n", res);
  return 0;
}
