#include <bits/stdc++.h>
using namespace std;
struct acm {
  long long a, b, g, s;
} xx[200010];
long long n, m, ans = -1, G, S;
long long cnt = 0;
long long fa[200010], b[200010];
long long find(long long x) { return x == fa[x] ? fa[x] : fa[x] = find(fa[x]); }
void baba(long long x, long long y) {
  long long fx = find(x), fy = find(y);
  fa[fx] = fy;
}
bool same(long long a, long long b) { return find(a) == find(b); }
bool cmp(acm p, acm q) {
  if (p.g != q.g) return p.g < q.g;
  return p.s < q.s;
}
int main() {
  scanf("%lld %lld %lld %lld", &n, &m, &G, &S);
  for (int i = 1; i <= m; i++) {
    scanf("%lld %lld %lld %lld", &xx[i].a, &xx[i].b, &xx[i].g, &xx[i].s);
    if (xx[i].a == xx[i].b) i--, m--;
  }
  sort(xx + 1, xx + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    cnt++;
    b[cnt] = i;
    long long t = cnt;
    while (t > 1 && xx[b[t]].s < xx[b[t - 1]].s) swap(b[t], b[t - 1]), t--;
    for (int j = 1; j <= n; j++) fa[j] = j;
    cnt = 0;
    for (int j = 1; j <= n; j++) {
      long long fx = find(xx[b[j]].a);
      long long fy = find(xx[b[j]].b);
      if (fx != fy)
        fa[fx] = fy;
      else
        continue;
      cnt++;
      b[cnt] = b[j];
      if (cnt == n - 1) break;
    }
    if (cnt == n - 1) {
      if (ans == -1)
        ans = G * xx[i].g + S * xx[b[n - 1]].s;
      else
        ans = min(G * xx[i].g + S * xx[b[n - 1]].s, ans);
    }
  }
  printf("%lld\n", ans);
}
