#include <bits/stdc++.h>
using namespace std;
int n, m;
int s, g;
struct data {
  int st, ed, g, s;
} eg[500500], ie[220];
bool cmp(data a, data b) { return a.g < b.g; }
bool cmps(data a, data b) { return a.s < b.s; }
int fa[330];
int find(int x) {
  int j = x, t;
  while (fa[x] != x) x = fa[x];
  while (fa[j] != x) t = fa[j], fa[j] = x, j = t;
  return x;
}
long long ans = 0x7fffffffffffffff;
int pos, tot;
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &g, &s);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d%d", &eg[i].st, &eg[i].ed, &eg[i].g, &eg[i].s);
  sort(eg + 1, eg + m + 1, cmp);
  int fx, fy;
  for (int i = 1; i <= m; ++i) {
    ie[++tot] = eg[i];
    pos = 0;
    for (int j = tot; j > 1 && ie[j].s < ie[j - 1].s; --j)
      swap(ie[j], ie[j - 1]);
    for (int j = 1; j <= n; ++j) fa[j] = j;
    for (int j = 1; j <= tot; ++j) {
      fx = find(ie[j].st);
      fy = find(ie[j].ed);
      if (fx == fy) continue;
      fa[fy] = fx;
      ie[++pos] = ie[j];
      if (pos == n - 1) break;
    }
    if (pos == n - 1)
      ans = min(ans, (long long)eg[i].g * g + (long long)ie[pos].s * s);
    tot = pos;
  }
  if (ans == 0x7fffffffffffffff)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}
