#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
const int MAXM = 50005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, m, G, S, now;
long long ans = INF;
int Read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x * 10) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void Put1(long long x) {
  if (x > 9) Put1(x / 10);
  putchar(x % 10 ^ 48);
}
void Put(long long x, char c = -1) {
  if (x < 0) putchar('-'), x = -x;
  Put1(x);
  if (c >= 0) putchar(c);
}
template <typename T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
struct edge {
  int u, v, g, s;
  bool operator<(const edge &px) const { return g < px.g; }
} e[MAXM], q[MAXN];
int f[MAXN];
int findSet(int x) {
  if (x != f[x]) f[x] = findSet(f[x]);
  return f[x];
}
void update(int x) {
  for (int i = now; i >= 2; --i) {
    if (q[i].s < q[i - 1].s)
      swap(q[i], q[i - 1]);
    else
      break;
  }
  for (int i = 1; i <= n; ++i) f[i] = i;
  int now1 = now, cnt = 0;
  now = 0;
  for (int i = 1; i <= now1; ++i) {
    int u = findSet(q[i].u), v = findSet(q[i].v);
    if (u != v) {
      cnt++;
      f[u] = v;
      q[++now] = q[i];
    }
  }
  if (cnt == n - 1) ans = Min(ans, 1ll * G * x + 1ll * S * q[now].s);
}
int main() {
  n = Read();
  m = Read();
  G = Read();
  S = Read();
  for (int i = 1; i <= m; ++i) {
    e[i].u = Read();
    e[i].v = Read();
    e[i].g = Read();
    e[i].s = Read();
  }
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; ++i) {
    q[++now] = e[i];
    update(e[i].g);
  }
  Put(ans == INF ? -1 : ans);
  return 0;
}
