#include <bits/stdc++.h>
using namespace std;
const int MAXN = 52;
int mp[MAXN][MAXN];
int minv[MAXN], maxv[MAXN];
bool gold[MAXN], silver[MAXN], bronze[MAXN];
long long dp[MAXN][MAXN];
int main() {
  int n, m, g1, g2, s1, s2;
  long long ans;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) mp[i][j] = INT_MAX;
  for (int i = 1; i <= n; i++)
    mp[i][i] = 0, minv[i] = INT_MAX, maxv[i] = INT_MIN;
  while (m--) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    mp[x][y] = mp[y][x] = c;
  }
  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++)
        if (mp[i][k] != INT_MAX && mp[k][j] != INT_MAX)
          mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j)
        mp[i][j] = mp[i][j] * 100 + i, minv[i] = min(minv[i], mp[i][j]),
        maxv[i] = max(maxv[i], mp[i][j]);
  ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && minv[i] < maxv[j]) {
        memset(gold, 0, sizeof(gold));
        memset(silver, 0, sizeof(silver));
        memset(bronze, 0, sizeof(bronze));
        for (int k = 1; k <= n; k++)
          if (k != i && k != j) {
            if (minv[k] < minv[i]) gold[k] = true;
            if (maxv[k] > maxv[j]) bronze[k] = true;
            for (int s = 1; s <= n; s++)
              if (mp[k][s] > minv[i] && mp[k][s] < maxv[j]) {
                silver[k] = true;
                break;
              }
          }
        gold[i] = true;
        bronze[j] = true;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int k = 1; k <= n; k++)
          for (int x = g2; x >= 0; x--)
            for (int y = s2; y >= 0; y--)
              if (dp[x][y] > 0) {
                if (gold[k]) dp[x + 1][y] += dp[x][y];
                if (silver[k]) dp[x][y + 1] += dp[x][y];
                if (!bronze[k]) dp[x][y] = 0;
              }
        for (int x = g1; x <= g2; x++)
          for (int y = s1; y <= s2; y++) ans += dp[x][y];
      }
  printf("%I64d\n", ans);
  return 0;
}
