#include <bits/stdc++.h>
using namespace std;
struct data {
  int u, v, g, s;
};
vector<data> edge;
int par[269];
bool cmp1(data x, data y) { return x.g < y.g; }
bool cmp2(data x, data y) { return x.s < y.s; }
int Find(int p) {
  if (par[p] == p) return p;
  return par[p] = Find(par[p]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long G, S;
  scanf("%lld%lld", &G, &S);
  for (int i = 0; i < m; i++) {
    int u, v, g, s;
    scanf("%d%d%d%d", &u, &v, &g, &s);
    edge.push_back({u, v, g, s});
  }
  sort(edge.begin(), edge.end(), cmp1);
  vector<data> cur;
  long long ans = 2e18;
  for (auto it : edge) {
    vector<data> tmp1 = cur;
    tmp1.push_back(it);
    sort(tmp1.begin(), tmp1.end(), cmp2);
    memset(par, 0, sizeof par);
    for (int i = 1; i <= n; i++) par[i] = i;
    vector<data> get;
    long long silver, gold = it.g, cnt = 0;
    for (auto i : tmp1) {
      int u = Find(i.u);
      int v = Find(i.v);
      if (u == v) continue;
      par[u] = v;
      get.push_back(i);
      cnt++;
      silver = i.s;
    }
    if (cnt == n - 1) ans = min(ans, silver * S + gold * G);
    cur = get;
  }
  if (ans == (2e18)) ans = -1;
  printf("%lld\n", ans);
  return 0;
}
