#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 5e4 + 20, mod = 1e9, inf = 4e18, maxm = 2e5 + 20;
const long double eps = 0.0001;
int n, m;
long long int G, S;
pair<pair<long long int, long long int>, pair<long long int, long long int> >
    e[N];
int par[N];
set<pair<long long int, long long int> > adj[N];
bool vis[N];
int mat[400][400];
long long int mx = 0, x, y;
multiset<long long int> st;
int getpar(int v) {
  if (par[v] == v) return v;
  return par[v] = getpar(par[v]);
}
inline bool merge(int u, int v) {
  if (getpar(u) == getpar(v)) return 0;
  par[par[u]] = par[v];
  return 1;
}
bool dfs(int v, int p) {
  vis[v] = 1;
  for (pair<long long int, long long int> u : adj[v]) {
    if (u.first == p) continue;
    if (vis[u.first]) {
      mx = u.second;
      x = v;
      y = u.first;
      return 1;
    }
    if (dfs(u.first, v)) {
      if (mx < u.second) {
        mx = u.second;
        x = v;
        y = u.first;
      }
      return 1;
    }
  }
  return 0;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> G >> S;
  for (int i = 1; i < n + 1; i++) par[i] = i;
  for (int i = 0; i < m; i++)
    cin >> e[i].second.first >> e[i].second.second >> e[i].first.first >>
        e[i].first.second;
  sort(e, e + m);
  long long int val = inf;
  int cnt = n;
  for (int i = 0; i < m; i++) {
    int u = e[i].second.first, v = e[i].second.second;
    if (u == v) continue;
    if (merge(u, v)) {
      cnt--;
      adj[u].insert({v, e[i].first.second});
      adj[v].insert({u, e[i].first.second});
      mat[u][v] = e[i].first.second;
      mat[v][u] = mat[u][v];
      st.insert(-e[i].first.second);
    } else {
      adj[u].insert({v, e[i].first.second});
      adj[v].insert({u, e[i].first.second});
      if (mat[u][v]) {
        if (mat[u][v] <= e[i].first.second) {
          adj[u].erase({v, e[i].first.second});
          adj[v].erase({u, e[i].first.second});
          continue;
        }
        adj[u].erase({v, mat[u][v]});
        adj[v].erase({u, mat[u][v]});
        auto it = st.find(-mat[u][v]);
        st.erase(it);
        mat[u][v] = e[i].first.second;
        mat[v][u] = mat[u][v];
        adj[v].insert({u, mat[u][v]});
        adj[u].insert({v, mat[u][v]});
        st.insert(-mat[u][v]);
        if (cnt == 1)
          val = min(val, G * e[i].first.first - S * (*(st.begin())));
        continue;
      }
      for (int i = 1; i < n + 1; i++) vis[i] = 0;
      mx = 0;
      dfs(u, -1);
      mat[u][v] = e[i].first.second;
      mat[v][u] = mat[u][v];
      adj[x].erase({y, mx});
      adj[y].erase({x, mx});
      mat[y][x] = 0;
      mat[x][y] = 0;
      st.insert(-e[i].first.second);
      auto it = st.find(-mx);
      st.erase(it);
    }
    if (st.size() > n - 1) cout << st.size() << " ";
    if (cnt == 1) val = min(val, G * e[i].first.first - S * (*(st.begin())));
  }
  if (cnt != 1) {
    cout << -1;
    return 0;
  }
  cout << val;
  return 0;
}
