#include <bits/stdc++.h>
using namespace std;
int n, m, G, S, E[50000 + 5][4], Ord[50000 + 5];
long long ans = 0x3f3f3f3f3f3f3f3fLL;
struct MST {
  int sz, cnt;
  vector<pair<int, int> > Go[200 + 5];
  void Init(int _sz) {
    sz = _sz, cnt = 0;
    for (int i = 1; i <= sz; i++) Go[i].clear();
  }
  void Remove(int x, int y) {
    for (pair<int, int> &p : Go[x])
      if (p.first == y) {
        swap(p, Go[x].back());
        Go[x].pop_back();
        break;
      }
  }
  bool Dfs(int z, int fa, int tar, pair<int, int> &res) {
    if (z == tar) {
      res = make_pair(-1, -1);
      return true;
    }
    for (int i = 0; i < Go[z].size(); i++) {
      const pair<int, int> &p = Go[z][i];
      if (p.first == fa) continue;
      if (Dfs(p.first, z, tar, res)) {
        if (res.first == -1 || p.second > Go[res.first][res.second].second)
          res = make_pair(z, i);
        return true;
      }
    }
    return false;
  }
  void Add(int u, int v, int w) {
    if (u == v) return;
    pair<int, int> mx;
    bool ok = Dfs(u, 0, v, mx);
    if (!ok) {
      cnt++;
      Go[u].emplace_back(v, w);
      Go[v].emplace_back(u, w);
      return;
    }
    if (Go[mx.first][mx.second].second > w) {
      int x = mx.first, y = Go[mx.first][mx.second].first;
      Remove(x, y), Remove(y, x);
      Go[u].emplace_back(v, w);
      Go[v].emplace_back(u, w);
    }
  }
  bool Complete() const { return cnt == sz - 1; }
  int MaxW() const {
    int res = 0;
    for (int i = 1; i <= sz; i++)
      for (const pair<int, int> &p : Go[i]) res = max(res, p.second);
    return res;
  }
} T;
int main() {
  scanf("%d%d%d%d", &n, &m, &G, &S);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", E[i], E[i] + 1, E[i] + 2, E[i] + 3);
    Ord[i] = i;
  }
  sort(Ord + 1, Ord + m + 1, [](int u, int v) { return E[u][2] < E[v][2]; });
  T.Init(n);
  for (int i = 1; i <= m; i++) {
    int j = Ord[i];
    int u = E[j][0], v = E[j][1], w = E[j][3];
    T.Add(u, v, w);
    if (T.Complete()) ans = min(ans, 1LL * G * E[j][2] + 1LL * S * T.MaxW());
  }
  if (ans == 0x3f3f3f3f3f3f3f3fLL)
    puts("-1");
  else
    printf("%lld\n", ans);
  return 0;
}
