#include <bits/stdc++.h>
using namespace std;
const int N = 210;
const int M = 50010;
const long long inf = 2000000000000000000ll;
int fa[N];
struct T {
  int g, s;
  int x, y;
} tt[M];
bool cmp(T a, T b) { return a.g < b.g; }
bool cmp2(T a, T b) { return a.s < b.s; }
int find(int x) {
  if (x == fa[x]) {
    return x;
  }
  return fa[x] = find(fa[x]);
}
vector<T> tx, tmp;
long long G, S;
long long calc() {
  long long g = 0, s = 0;
  for (int i = 0; i < tx.size(); i++) {
    g = max(g, (long long)tx[i].g);
    s = max(s, (long long)tx[i].s);
  }
  return g * G + s * S;
}
T a[N];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  cin >> G >> S;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &tt[i].x, &tt[i].y);
    scanf("%d%d", &tt[i].g, &tt[i].s);
  }
  sort(tt + 1, tt + 1 + m, cmp);
  long long ans = inf;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      fa[j] = j;
    }
    int ts = 0;
    int flag = 0;
    for (int j = 0; j < tx.size(); j++) {
      if (flag) {
        a[ts++] = tx[j];
      } else {
        if (tt[i].s <= tx[j].s) {
          a[ts++] = tt[i];
          flag = 1;
        }
        a[ts++] = tx[j];
      }
    }
    if (!flag) {
      a[ts++] = tt[i];
    }
    tx.clear();
    for (int j = 0; j < ts; j++) {
      int u = find(a[j].x), v = find(a[j].y);
      if (u != v) {
        fa[u] = v;
        tx.push_back(a[j]);
      }
    }
    if (tx.size() == n - 1) {
      ans = min(ans, calc());
    }
  }
  if (ans == inf) {
    printf("-1\n");
  } else {
    cout << ans << endl;
  }
  return 0;
}
