#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const int maxm = 5e4 + 5;
int readint() {
  int x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    (s = getchar());
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    (s = getchar());
  }
  return x * f;
}
struct edge {
  int u, v, gold, silver;
} e[maxm];
int fa[maxn], st[maxn], top;
int findset(int x) {
  if (fa[x] != x) fa[x] = findset(fa[x]);
  return fa[x];
}
bool cmp(const edge &x, const edge &y) {
  if (x.gold == y.gold) return x.silver < y.silver;
  return x.gold < y.gold;
}
int main() {
  int n = readint(), m = readint(), g = readint(), s = readint();
  for (int i = 1; i <= m; i++) {
    e[i].u = readint(), e[i].v = readint();
    e[i].gold = readint(), e[i].silver = readint();
  }
  sort(e + 1, e + m + 1, cmp);
  long long ans = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      fa[j] = j;
    }
    st[++top] = i;
    for (int j = top; j >= 2; j--) {
      if (e[st[j]].silver < e[st[j - 1]].silver) swap(st[j], st[j - 1]);
    }
    int cnt = 0;
    for (int j = 1; j <= top; j++) {
      int u = e[st[j]].u, v = e[st[j]].v;
      int fu = findset(u), fv = findset(v);
      if (fu == fv) continue;
      fa[fu] = fv;
      st[++cnt] = st[j];
      if (cnt == n - 1) break;
    }
    if (cnt == n - 1)
      ans = min(ans, 1ll * g * e[i].gold + 1ll * s * e[st[cnt]].silver);
    top = cnt;
  }
  if (ans == 0x3f3f3f3f3f3f3f3f)
    puts("-1");
  else
    cout << ans;
  return 0;
}
