#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200 + 9;
const int MAXM = 50000 + 99;
struct E {
  int x, y, g, s;
} e[MAXM];
int n, m, g, s, k;
int par[MAXN];
long long ans = LONG_LONG_MAX;
bool cmpg(const E& a, const E& b) { return a.g < b.g; }
bool cmps(const E& a, const E& b) { return a.s < b.s; }
int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool merge(int x, int y) {
  x = root(x), y = root(y);
  if (x == y) return false;
  if (par[x] < par[y])
    par[x] += par[y], par[y] = x;
  else
    par[y] += par[x], par[x] = y;
  return true;
}
int main() {
  cin >> n >> m >> g >> s;
  for (int i = 0, _n = (m); i < _n; i++)
    cin >> e[i].x >> e[i].y >> e[i].g >> e[i].s, e[i].x--, e[i].y--;
  sort(e, e + m, cmpg);
  for (int z = 0, _n = (m); z < _n; z++) {
    e[k++] = e[z];
    inplace_merge(e, e + k - 1, e + k, cmps);
    int gu = 0, su = 0, t = 0;
    memset(par, -1, sizeof par);
    for (int i = 0, _n = (k); i < _n; i++)
      if (merge(e[i].x, e[i].y))
        (gu = max(gu, e[i].g)), (su = max(su, e[i].s)), e[t++] = e[i];
    k = t;
    if (k == n - 1) (ans = min(ans, (long long)g * gu + (long long)s * su));
  }
  cout << (ans == LONG_LONG_MAX ? -1 : ans) << endl;
  {
    int _;
    cin >> _;
  }
}
