#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
  int from, to;
  long long wa, wb;
} e[500500], s[500500];
long long a, b;
int top, cnt;
int f[11000];
long long ans = 0x7fffffffffffffffll;
bool cmp(node a, node b) {
  if (a.wa == b.wa) return a.wb < b.wb;
  return a.wa < b.wa;
}
bool cmp2(node a, node b) {
  if (a.wb == b.wb) return a.wa < b.wa;
  return a.wb < b.wb;
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  cin >> a >> b;
  for (int i = 1; i <= m; i++)
    cin >> e[i].from >> e[i].to >> e[i].wa >> e[i].wb;
  sort(e + 1, e + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) f[j] = j;
    s[++top] = e[i];
    cnt = 0;
    for (int j = top; j >= 2; j--)
      if (s[j].wb < s[j - 1].wb) swap(s[j], s[j - 1]);
    for (int j = 1; j <= top; j++) {
      if (find(s[j].from) != find(s[j].to))
        s[++cnt] = s[j], f[find(s[j].from)] = find(s[j].to);
      if (cnt == n - 1) break;
    }
    if (cnt == n - 1)
      ans = min(ans, (long long)e[i].wa * a + (long long)s[cnt].wb * b);
    top = cnt;
  }
  if (ans == 0x7fffffffffffffffll)
    printf("-1\n");
  else
    cout << ans << endl;
  return 0;
}
