#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, w[80][80], v1[80], v2[80], f[20000010], id[80], t;
int d1(int x) {
  v1[x] = 1;
  int s = 1;
  for (int i = 1; i <= n; i++)
    if (w[x][i] == a && !v1[i]) s += d1(i);
  return s;
}
void d2(int x) {
  v2[x] = 1;
  id[x] = t;
  for (int i = 1; i <= n; i++)
    if (w[x][i] == a && !v2[i]) d2(i);
}
int va(int x, int y) { return x * n + y - 1; }
queue<int> q1, q2;
int main() {
  cin >> n >> m >> a >> b;
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    w[x][y] = w[y][x] = z;
  }
  int ct = 0;
  for (int i = 1; i <= n; i++)
    if (!v1[i] && d1(i) >= 4) {
      t = ++ct;
      d2(i);
    }
  int tp = ct;
  memset(v1, 0, sizeof(v1));
  for (int i = 1; i <= n; i++)
    if (!v1[i] && d1(i) < 4) {
      t = ++ct;
      d2(i);
    }
  memset(f, 127, sizeof(f));
  f[va(0, 1)] = 0;
  q1.push(va(0, 1));
  q2.push(va(0, 1));
  while (!q1.empty() || !q2.empty()) {
    int x;
    if (q1.empty()) {
      x = q2.front();
      q2.pop();
    } else if (q2.empty()) {
      x = q1.front();
      q1.pop();
    } else if (f[q1.front()] > f[q2.front()]) {
      x = q2.front();
      q2.pop();
    } else {
      x = q1.front();
      q1.pop();
    }
    int c = x / n, d = x % n + 1;
    for (int i = 1; i <= n; i++) {
      if (!w[d][i] || id[i] <= tp && (c & (1 << (id[i] - 1))) ||
          (id[i] == id[d] && w[d][i] == b))
        continue;
      int nt = va(c, i);
      if (id[d] <= tp && id[d] != id[i]) nt = va(c | (1 << (id[d] - 1)), i);
      if (f[nt] > f[x] + w[d][i]) {
        f[nt] = f[x] + w[d][i];
        if (w[d][i] == a)
          q1.push(nt);
        else
          q2.push(nt);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int r = 1e9;
    for (int j = 0; j < (1 << tp); j++) r = min(r, f[va(j, i)]);
    cout << r << ' ';
  }
}
