#include <bits/stdc++.h>
using namespace std;
struct st {
  int x, y, a, b;
  bool operator<(const st& B) const { return a < B.a; }
} a[50005], q[205];
int N, M, A, B, f[205];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void init() {
  scanf("%d%d%d%d", &N, &M, &A, &B);
  for (int i = 1; i <= M; i++)
    scanf("%d%d%d%d", &a[i].x, &a[i].y, &a[i].a, &a[i].b);
  sort(a + 1, a + M + 1);
}
void doit() {
  long long ans = 2e18;
  for (int i = 1, t = 0, s; i <= M; i++) {
    q[++t] = a[i], s = 0;
    for (int j = t - 1; j && q[j + 1].b < q[j].b; j--) swap(q[j], q[j + 1]);
    for (int j = 1; j <= N; j++) f[j] = j;
    for (int j = 1, x, y; s < N - 1 && j <= t; j++)
      if ((x = find(q[j].x)) != (y = find(q[j].y))) f[x] = y, q[++s] = q[j];
    if (s == N - 1) ans = min(ans, 1ll * A * a[i].a + 1ll * B * q[s].b);
    t = s;
  }
  printf("%I64d\n", ans < 2e18 ? ans : -1);
}
int main() {
  init();
  doit();
  return 0;
}
