#include <bits/stdc++.h>
using namespace std;
int x[50010];
int y[50010];
int z[50010];
int t[50010];
int root[210];
bool cmp(int x, int y) { return z[x] < z[y]; }
int findd(int x) {
  if (root[x] == -1) return x;
  return root[x] = findd(root[x]);
}
long long int INF = 1LL << 61;
vector<int> a;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    qu[4];
int main() {
  int n, m, g, s, i;
  scanf("%d %d", &n, &m);
  scanf("%d %d", &g, &s);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &x[i], &y[i], &z[i], &t[i]);
    a.push_back(i);
  }
  sort(a.begin(), a.end(), cmp);
  long long ans = INF;
  for (int pl = 0; pl < a.size(); pl++) {
    i = a[pl];
    qu[pl & 1].push(pair<int, int>(t[i], i));
    int num = n, cur = 0;
    memset(root, -1, sizeof root);
    while (!qu[pl & 1].empty()) {
      int u = x[qu[pl & 1].top().second], v = y[qu[pl & 1].top().second];
      if (findd(u) == findd(v)) {
        qu[pl & 1].pop();
        continue;
      }
      num--;
      cur = max(qu[pl & 1].top().first, cur);
      root[findd(v)] = findd(u);
      qu[(pl + 1) & 1].push(qu[pl & 1].top());
      qu[pl & 1].pop();
    }
    if (num == 1) ans = min(ans, 1LL * cur * s + 1LL * z[i] * g);
  }
  if (ans != INF)
    cout << ans;
  else
    cout << "-1";
}
