#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u;
  int v;
  long long s, g;
} g[50005], q[205];
int fa[205];
inline bool cmp(Edge x, Edge y) { return x.g < y.g; }
inline int find(int x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = find(fa[x]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long cg, cs;
  scanf("%I64d%I64d", &cg, &cs);
  for (int i = 0; i < m; i++)
    scanf("%d%d%I64d%I64d", &g[i].u, &g[i].v, &g[i].g, &g[i].s);
  sort(g, g + m, cmp);
  int t = 0, s = 0;
  long long ans = 2e18 + 7;
  for (int i = 0; i < m; i++) {
    q[++t] = g[i];
    s = 0;
    for (int j = t - 1; j && q[j + 1].s < q[j].s; j--) swap(q[j], q[j + 1]);
    for (int j = 1; j <= n; j++) fa[j] = j;
    for (int j = 1, x, y; s < n - 1 && j <= t; j++)
      if ((x = find(q[j].u)) != (y = find(q[j].v))) fa[x] = y, q[++s] = q[j];
    if (s == n - 1) ans = min(ans, cg * g[i].g + cs * q[s].s);
    t = s;
  }
  printf("%I64d\n", ans < 2e18 ? ans : -1);
  return 0;
}
