#include <bits/stdc++.h>
using namespace std;
const int max_n = 50001;
int n, m, i, j, k, Y, x[max_n], y[max_n], p[max_n], id[max_n], g[max_n],
    s[max_n], v[max_n], a[201][201];
long long G, S, ans = -1;
multiset<int> SET;
multiset<int>::iterator it;
int cmp(int a, int b) { return g[a] < g[b]; }
void rev(int x) {
  if (p[x] != -1) {
    rev(p[x]);
    p[p[x]] = x;
  }
  p[x] = -1;
}
int main() {
  scanf("%d%d%lld%lld", &n, &m, &G, &S);
  for (i = 0; i < m; i++) {
    scanf("%d%d%d%d", &x[i], &y[i], &g[i], &s[i]);
    id[i] = i;
  }
  for (i = 1; i <= n; i++) p[i] = -1;
  sort(id, id + m, cmp);
  for (i = 0; i < m; i++) {
    int xx = x[id[i]], yy = y[id[i]], gg = g[id[i]], ss = s[id[i]], x2, y2;
    if (xx == yy) continue;
    x2 = xx;
    while (p[x2] != -1) x2 = p[x2];
    y2 = yy;
    while (p[y2] != -1) y2 = p[y2];
    if (x2 == y2) {
      for (int i = 1; i <= n; ++i) v[i] = 0;
      x2 = xx;
      v[x2]++;
      while (p[x2] != -1) {
        x2 = p[x2];
        v[x2]++;
      }
      y2 = yy;
      v[y2] += 2;
      while (p[y2] != -1) {
        y2 = p[y2];
        v[y2] += 2;
      }
      int w = -1, alt;
      x2 = xx;
      while (p[x2] != -1) {
        if (v[x2] != 3) {
          if (w == -1 || a[w][p[w]] < a[x2][p[x2]]) {
            w = x2;
            alt = xx;
          }
        } else
          break;
        x2 = p[x2];
      }
      y2 = yy;
      while (p[y2] != -1) {
        if (v[y2] != 3) {
          if (w == -1 || a[w][p[w]] < a[y2][p[y2]]) {
            w = y2;
            alt = yy;
          }
        } else
          break;
        y2 = p[y2];
      }
      if (w != -1 && a[w][p[w]] > ss) {
        SET.erase(SET.find(a[w][p[w]]));
        p[w] = -1;
        rev(xx);
        p[xx] = yy;
        SET.insert(ss);
        a[xx][yy] = a[yy][xx] = ss;
      }
    } else {
      a[xx][yy] = a[yy][xx] = ss;
      rev(xx);
      p[xx] = yy;
      SET.insert(ss);
    }
    if (SET.size() == n - 1) {
      if (ans == -1 || ans > G * gg + S * (*SET.rbegin()))
        ans = G * gg + S * (*SET.rbegin());
    }
  }
  cout << ans << endl;
  return 0;
}
