#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, c1, c2;
};
int parent[205];
int findSet(int u) {
  while (parent[u] > 0) u = parent[u];
  return u;
}
void Union(int u, int v) {
  int x = parent[u] + parent[v];
  if (parent[u] > parent[v]) {
    parent[v] = x;
    parent[u] = v;
  } else {
    parent[v] = u;
    parent[u] = x;
  }
}
set<int> DSK[205];
int valid[205][205];
void setValid(int u, int v, int val) {
  valid[u][v] = val;
  valid[v][u] = val;
  if (val > 0) {
    DSK[u].insert(v);
    DSK[v].insert(u);
  } else {
    DSK[u].erase(v);
    DSK[v].erase(u);
  }
}
int trace[205];
int vi[205];
void DFS(int u) {
  vi[u] = 1;
  for (int v : DSK[u]) {
    if (!vi[v] && valid[u][v] != 0) {
      trace[v] = u;
      DFS(v);
    }
  }
}
pair<int, int> findMaxCycle(int u, int v) {
  int pre = v;
  pair<int, int> res = {0, 0};
  while (v != u) {
    v = trace[v];
    if (valid[res.first][res.second] < valid[v][pre]) {
      res.first = v;
      res.second = pre;
    }
    pre = v;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, G, S;
  cin >> n >> m >> G >> S;
  vector<edge> edges;
  for (int i = 0; i < m; i++) {
    int u, v, c1, c2;
    cin >> u >> v >> c1 >> c2;
    edges.push_back({u, v, c1, c2});
  }
  sort(edges.begin(), edges.end(),
       [](const edge &A, const edge &B) { return A.c1 < B.c1; });
  multiset<int, greater<int>> Set;
  multiset<int, greater<int>>::iterator it;
  long long res = LLONG_MAX;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int u = edges[i].u;
    int v = edges[i].v;
    int c1 = edges[i].c1;
    int c2 = edges[i].c2;
    int U = findSet(edges[i].u);
    int V = findSet(edges[i].v);
    if (U != V) {
      cnt++;
      Union(U, V);
      setValid(u, v, c2);
      Set.insert(c2);
    } else {
      fill(vi + 1, vi + 1 + n, 0);
      DFS(u);
      pair<int, int> e = findMaxCycle(u, v);
      if (valid[e.first][e.second] > c2) {
        it = Set.find(valid[e.first][e.second]);
        Set.erase(it);
        setValid(e.first, e.second, 0);
        setValid(u, v, c2);
        Set.insert(c2);
      }
    }
    if (cnt >= n - 1) {
      res = min(res, 1LL * G * c1 + 1LL * S * (*Set.begin()));
    }
  }
  if (res == LLONG_MAX)
    cout << -1;
  else
    cout << res;
}
