#include <bits/stdc++.h>
using namespace std;
const int MAXN = 202;
const int MAXM = 50005;
struct edge {
  int a, b;
  long long int g, s;
  edge(int a_ = 0, int b_ = 0, long long int g_ = 0LL, long long int s_ = 0LL) {
    a = a_, b = b_, g = g_, s = s_;
  }
};
int N, M, cnt;
int dad[MAXN];
long long int G, S, res = 1LL << 62;
edge g[MAXM];
edge way[MAXM];
inline bool compare(const edge &a, const edge &b) { return a.g < b.g; }
inline int find(int a) {
  if (a == dad[a]) return a;
  return dad[a] = find(dad[a]);
}
int main() {
  scanf(" %d %d %I64d %I64d", &N, &M, &G, &S);
  for (int i = 1; i <= M; i++) {
    scanf(" %d %d %I64d %I64d", &way[i].a, &way[i].b, &way[i].g, &way[i].s);
    way[i].g *= G;
    way[i].s *= S;
  }
  sort(way + 1, way + M + 1, compare);
  for (int i = 1; i <= M; i++) {
    g[++cnt] = way[i];
    for (int j = cnt; j > 1; j--) {
      if (g[j].s < g[j - 1].s)
        swap(g[j], g[j - 1]);
      else
        break;
    }
    if (i >= N - 1) {
      long long int ss;
      for (int j = 1; j <= N; j++) dad[j] = j;
      int c = 0;
      int ncnt = 0;
      for (int j = 1; j <= cnt; j++)
        if (find(g[j].a) != find(g[j].b)) {
          c++;
          g[++ncnt] = g[j];
          ss = g[j].s;
          dad[find(g[j].a)] = g[j].b;
        }
      cnt = ncnt;
      if (c == N - 1) res = min(res, way[i].g + ss);
    }
  }
  if (res == 1LL << 62)
    printf("-1\n");
  else
    printf("%I64d\n", res);
  return 0;
}
