#include <bits/stdc++.h>
using namespace std;
const int maxm = 50005;
const int maxn = 256;
const long long infll = 1LL << 62;
vector<pair<int, int> > t[maxn];
int x[maxm], y[maxm], g[maxm], s[maxm];
int id[maxm];
int n, m, G, S;
bool cmp(int x, int y) { return g[x] < g[y]; }
int p[maxn], pe[maxn];
void dfs(int x, int z) {
  for (__typeof((t[x]).begin()) it = (t[x]).begin(); it != (t[x]).end(); ++it)
    if (it->first != z)
      p[it->first] = x, pe[it->first] = it->second, dfs(it->first, x);
}
int sum;
int calc(int x, int p) {
  int res = 1;
  for (int i = 0; i < (int((t[x]).size())); ++i)
    if (t[x][i].first != p)
      res += calc(t[x][i].first, x), sum = max(sum, s[t[x][i].second]);
  return res;
}
void printt() {
  printf("tree\n");
  for (int i = 0; i < (n); ++i) {
    printf("%d : ", i);
    for (__typeof((t[i]).begin()) it = (t[i]).begin(); it != (t[i]).end(); ++it)
      printf("(%d, %d) ", it->first, it->second);
    puts("");
  }
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d %d", &G, &S);
  for (int i = 0; i < (m); ++i)
    scanf("%d %d %d %d", x + i, y + i, g + i, s + i), --x[i], --y[i];
  for (int i = 0; i < (m); ++i) id[i] = i;
  sort(id, id + m, cmp);
  long long res = infll;
  for (int i = 0; i < (m); ++i) {
    int e = id[i];
    if (x[e] == y[e]) continue;
    long long cur = (long long)G * g[e];
    for (int i = 0; i < (n); ++i) p[i] = -1;
    dfs(x[e], -1);
    if (p[y[e]] != -1) {
      int best = 0, ee;
      for (int z = y[e]; p[z] != -1; z = p[z])
        if (best < s[pe[z]]) best = s[pe[z]], ee = pe[z];
      if (best > s[e]) {
        t[x[ee]].erase(
            find(t[x[ee]].begin(), t[x[ee]].end(), make_pair(y[ee], ee)));
        t[y[ee]].erase(
            find(t[y[ee]].begin(), t[y[ee]].end(), make_pair(x[ee], ee)));
        t[x[e]].push_back(make_pair(y[e], e));
        t[y[e]].push_back(make_pair(x[e], e));
      }
    } else {
      t[x[e]].push_back(make_pair(y[e], e));
      t[y[e]].push_back(make_pair(x[e], e));
    }
    sum = 0;
    if (calc(0, -1) == n) {
      res = min(res, cur + (long long)S * sum);
    }
  }
  if (res == infll)
    printf("-1\n");
  else
    cout << res << endl;
  return 0;
}
