#include <bits/stdc++.h>
using namespace std;
const int maxn = 205, maxm = 50005;
long long tot = 0, g0, s0, n, m, G, S, fa[maxn];
struct pic {
  int x;
  int y;
  int g;
  int s;
} sz[maxm * 2];
long long dl[maxn], top = 0;
long long ans = -1;
inline long long get(int x) { return (fa[x] == x) ? x : fa[x] = get(fa[x]); }
inline bool cmp(pic cp1, pic cp2) { return cp1.g < cp2.g; }
int main() {
  scanf("%lld%lld", &n, &m);
  scanf("%lld%lld", &G, &S);
  for (register int i = 1; i <= m; i++) {
    scanf("%lld%lld%lld%lld", &sz[i].x, &sz[i].y, &sz[i].g, &sz[i].s);
  }
  sort(sz + 1, sz + m + 1, cmp);
  for (register int i = 1; i <= m; i++) {
    for (register int j = 1; j <= n; j++) fa[j] = j;
    dl[++top] = i;
    for (register int j = top; j >= 2; j--) {
      if (sz[dl[j]].s < sz[dl[j - 1]].s) swap(dl[j], dl[j - 1]);
    }
    tot = 0;
    for (register int j = 1; j <= top; j++) {
      int u = get(sz[dl[j]].x), v = get(sz[dl[j]].y);
      if (u == v) continue;
      fa[v] = u;
      dl[++tot] = dl[j];
      if (tot == n - 1) break;
    }
    if (tot == n - 1) {
      if (ans == -1)
        ans = G * sz[i].g + S * sz[dl[n - 1]].s;
      else
        ans = min(ans, G * sz[i].g + S * sz[dl[n - 1]].s);
    }
    top = tot;
  }
  printf("%lld", ans);
  return 0;
}
