#include <bits/stdc++.h>
using namespace std;
const int maxn = 315, maxm = 200015;
struct ll {
  int x, y, g, s;
};
int _x, _y, _g, _s, len, n, m, A, B, now, yy;
ll e[maxm];
long long res, oo;
int tt[maxn], ts;
int c[maxn][maxn];
multiset<int> aa;
multiset<int>::iterator iter;
bool flag;
bool comp(ll a, ll b) { return a.g < b.g; }
void dfs(int dep, int pos, int jj, int f1, int f2) {
  tt[dep] = pos;
  if (dep == e[pos].y) {
    flag = true;
    if (jj > e[pos].s) {
      c[f1][f2] = 0;
      c[f2][f1] = 0;
      c[e[pos].x][e[pos].y] = e[pos].s;
      c[e[pos].y][e[pos].x] = e[pos].s;
      aa.insert(e[pos].s);
      iter = aa.find(jj);
      aa.erase(iter);
    }
    return;
  }
  for (int i = 1; i <= n; i++)
    if (c[dep][i] != 0 && tt[i] != pos) {
      if (c[dep][i] < jj)
        dfs(i, pos, jj, f1, f2);
      else
        dfs(i, pos, c[dep][i], dep, i);
      if (flag == true) return;
    }
}
int main() {
  scanf("%d %d", &n, &m);
  res = 2000000000;
  res *= res;
  res *= 10LL;
  oo = res;
  scanf("%d %d", &A, &B);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &_x, &_y, &_g, &_s);
    if (_x != _y) {
      len++;
      e[len].x = _x;
      e[len].y = _y;
      e[len].g = _g;
      e[len].s = _s;
    }
  }
  sort(e + 1, e + len + 1, comp);
  for (int i = 1; i <= len; i++) {
    flag = false;
    if (i == 7) ts++;
    dfs(e[i].x, i, 0, 0, 0);
    if (!flag) {
      now++;
      c[e[i].x][e[i].y] = e[i].s;
      c[e[i].y][e[i].x] = e[i].s;
      aa.insert(e[i].s);
    }
    iter = aa.end();
    iter--;
    yy = *iter;
    if (now == n - 1 && res > (long long)(A)*e[i].g + (long long)(B)*yy)
      res = (long long)(A)*e[i].g + (long long)(B)*yy;
  }
  if (res == oo) res = -1;
  cout << res << endl;
  return 0;
}
