#include <bits/stdc++.h>
using namespace std;
struct ed {
  long long x, y, a, b;
} e[50100];
bool cmp_a(ed u, ed v) { return u.a < v.a; }
bool cmp_b(ed u, ed v) { return u.b < v.b; }
long long p[300];
long long root(long long u) { return u == p[u] ? u : p[u] = root(p[u]); }
long long BIG = 2e18 + 7;
int main() {
  long long n, m;
  scanf("%I64d %I64d", &n, &m);
  long long g, s, ans = BIG;
  scanf("%I64d %I64d", &g, &s);
  for (long long i = 0; i < m; i++) {
    scanf("%I64d %I64d %I64d %I64d", &e[i].x, &e[i].y, &e[i].a, &e[i].b);
    e[i].x--;
    e[i].y--;
  }
  sort(e, e + m, cmp_a);
  set<pair<long long, long long> > t;
  for (long long i = 0; i < m; i++) {
    t.insert({e[i].b, i});
    for (long long i = 0; i < n; i++) p[i] = i;
    vector<pair<long long, long long> > toDel;
    long long connected = 0, silver_cost = 0;
    for (pair<long long, long long> j : t) {
      long long v = e[j.second].x;
      long long u = e[j.second].y;
      if (root(v) != root(u)) {
        p[root(v)] = root(u);
        connected++;
        silver_cost = max(silver_cost, j.first);
        if (connected == n - 1) ans = min(ans, g * e[i].a + s * silver_cost);
      } else {
        toDel.push_back(j);
      }
    }
    for (pair<long long, long long> j : toDel) t.erase(j);
  }
  if (ans == BIG) ans = -1;
  printf("%I64d ", ans);
  return 0;
}
