#include <bits/stdc++.h>
using namespace std;
int fa[210];
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
struct Line {
  int u, v, val1, val2;
} l[51000], sta[210];
bool cmp1(Line a, Line b) {
  if (a.val1 == b.val1) return a.val2 < b.val2;
  return a.val1 < b.val1;
}
bool cmp2(Line a, Line b) { return a.val2 < b.val2; }
int n, m, top;
int G, S;
int main() {
  scanf("%d%d%d%d", &n, &m, &G, &S);
  for (int i = 1; i <= m; i++)
    cin >> l[i].u >> l[i].v >> l[i].val1 >> l[i].val2;
  sort(l + 1, l + m + 1, cmp1);
  long long ans = 0x3f3f3f3f3f3f3f3fll;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) fa[j] = j;
    sta[++top] = l[i];
    for (int j = top; j >= 2; j--)
      if (sta[j].val2 < sta[j - 1].val2) swap(sta[j], sta[j - 1]);
    int cnt = 0;
    for (int j = 1; j <= top; j++) {
      int u = find(sta[j].u), v = find(sta[j].v);
      if (u != v) {
        fa[u] = v;
        sta[++cnt] = sta[j];
        if (cnt == n - 1) break;
      }
    }
    if (cnt == n - 1)
      ans = min(ans, (long long)G * l[i].val1 + (long long)S * sta[cnt].val2);
    top = cnt;
  }
  if (ans == 0x3f3f3f3f3f3f3f3fll)
    puts("-1");
  else
    printf("%I64d\n", ans);
}
