#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct edge {
  long long u, v, g, s;
};
edge p[50005];
long long n, m, fa[205];
long long use[205], len, used[205];
bool cmp2(long long x, long long y) { return p[x].s < p[y].s; }
long long getfa(long long x) { return fa[x] == x ? x : (fa[x] = getfa(fa[x])); }
void merge(long long x, long long y) {
  x = getfa(x);
  y = getfa(y);
  if (x != y) {
    fa[x] = y;
  }
}
long long check() {
  for (long long i = 1; i <= n; i++) fa[i] = i;
  for (long long i = 1; i <= len; i++) used[i] = 0;
  long long cnt = 1;
  for (long long i = 1; i <= len; i++) {
    long long nu = use[i];
    edge u = p[nu];
    if (getfa(u.u) != getfa(u.v)) {
      merge(u.u, u.v);
      used[i] = 1;
      if (++cnt == n) {
        len = 0;
        for (long long j = 1; j <= i; j++) {
          if (used[j]) use[++len] = use[j];
        }
        return u.s;
      }
    }
  }
  long long t = len;
  len = 0;
  for (long long j = 1; j <= t; j++) {
    if (used[j]) use[++len] = use[j];
  }
  return -1;
}
bool cmp1(edge x, edge y) { return x.g < y.g; }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long g, s;
  cin >> n >> m >> g >> s;
  for (long long i = 1; i <= m; i++) {
    cin >> p[i].u >> p[i].v >> p[i].g >> p[i].s;
  }
  sort(p + 1, p + m + 1, cmp1);
  long long ans = 2e18;
  for (long long i = 1; i <= m; i++) {
    use[++len] = i;
    for (long long j = len - 1; j >= 0; j--) {
      if (p[use[j]].s < p[use[len]].s) {
        for (long long k = len; k > j + 1; k--) use[k] = use[k - 1];
        use[j + 1] = i;
        break;
      }
    }
    long long t = check();
    if (t == -1) continue;
    ans = min(ans, p[i].g * g + t * s);
  }
  if (ans == 2e18) {
    cout << -1;
  } else
    cout << ans;
  return 0;
}
