#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int M = 50005;
const long long INF = 2e18;
inline int read() {
  int v = 0, c = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') c = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    v = v * 10 + ch - 48;
    ch = getchar();
  }
  return v * c;
}
struct edge {
  int from;
  int to;
  int gi;
  int si;
} e[M];
int n, m, G, S;
int fa[N];
int top;
edge sta[N], ss[N];
long long ans = INF;
inline int getf(int x) { return fa[x] == x ? x : fa[x] = getf(fa[x]); }
inline bool cmp(edge x, edge y) {
  return x.gi < y.gi || (x.gi == y.gi && x.si < y.si);
}
int main() {
  n = read(), m = read(), G = read(), S = read();
  for (int i = 1; i <= m; ++i) {
    e[i].from = read();
    e[i].to = read();
    e[i].gi = read();
    e[i].si = read();
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; ++i) {
    sta[++top] = e[i];
    int asg = e[i].gi, ass = 0;
    for (int j = top; j > 1; --j)
      if (sta[j - 1].si > sta[j].si) swap(sta[j], sta[j - 1]);
    for (int i = 1; i <= n; ++i) fa[i] = i;
    int cnt = 0;
    for (int i = 1; i <= top; ++i) {
      int x = getf(sta[i].from), y = getf(sta[i].to);
      if (x == y) continue;
      fa[x] = y;
      ss[++cnt] = sta[i];
      ass = sta[i].si;
      if (cnt == n - 1) break;
    }
    if (cnt == n - 1) ans = min(ans, 1ll * G * asg + 1ll * S * ass);
    top = cnt;
    memcpy(sta, ss, sizeof(sta));
  }
  if (ans != INF)
    printf("%lld\n", ans);
  else
    puts("-1");
  return 0;
}
