#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
  *OS++ = x;
  if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                              IS == IT ? EOF : *IS++)
                            : *IS++);
       c < '0' || c > '9';
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15),
      c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                      IS == IT ? EOF : *IS++)
                    : *IS++))
    ;
  x *= f;
}
inline void rds(char *s, int &x) {
  for (c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++);
       c < '0' || c > '9';
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    ;
  for (x = 0; c >= '0' && c <= '9';
       s[++x] = c, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                                   IS == IT ? EOF : *IS++)
                                 : *IS++))
    ;
}
template <class I>
inline void print(I x, char k = '\n') {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) ch[++t] = x % 10 + '0', x /= 10;
  while (t) pc(ch[t--]);
  pc(k);
}
struct Flush {
  ~Flush() { flush(); }
} flusher;
}  // namespace io
using io::print;
using io::rd;
using io::rds;
template <class I>
inline I Min(I x, I y) {
  return x < y ? x : y;
}
template <class I>
inline I Max(I x, I y) {
  return x > y ? x : y;
}
template <class I>
inline void Swap(I &x, I &y) {
  x ^= y ^= x ^= y;
}
const int INF = 1e9;
const int N = 71;
const int M = (1 << 17) + 3;
int A, B;
vector<pair<int, int> > g[N];
int compId[N];
int n, m;
int a[N][N];
int dp[N][M];
int dist[N];
bool used[N];
int main() {
  scanf("%d%d%d%d", &n, &m, &A, &B);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = (i == j ? 0 : INF);
  while (m--) {
    int v, u, w;
    scanf("%d%d%d", &v, &u, &w);
    v--;
    u--;
    g[v].push_back(make_pair(u, w));
    g[u].push_back(make_pair(v, w));
    if (w == A) {
      a[v][u] = a[u][v] = 1;
    }
  }
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
  m = 0;
  for (int i = 0; i < n; i++) compId[i] = -1;
  for (int v = 0; v < n; v++) {
    bool ok = true;
    for (int i = 0; i < v; i++) ok &= a[v][i] == INF;
    if (!ok) continue;
    int sz = 0;
    for (int i = 0; i < n; i++)
      if (a[v][i] < INF) sz++;
    if (sz < 4) continue;
    for (int i = 0; i < n; i++)
      if (a[v][i] < INF) compId[i] = m;
    m++;
  }
  if (m > 17) throw;
  for (int v = 0; v < n; v++)
    for (int mask = 0; mask < (1 << m); mask++) dp[v][mask] = INF;
  dp[0][(compId[0] == -1 ? 0 : (1 << compId[0]))] = 0;
  for (int mask = 0; mask < (1 << m); mask++) {
    for (int v = 0; v < n; v++) dist[v] = dp[v][mask];
    for (int i = 0; i < n; i++) used[i] = false;
    for (int it = 0; it < n; it++) {
      int v = -1;
      for (int i = 0; i < n; i++) {
        if (used[i]) continue;
        if (v == -1 || dist[v] > dist[i]) v = i;
      }
      used[v] = 1;
      if (dist[v] == INF) break;
      for (pair<int, int> e : g[v]) {
        int u = e.first;
        if (used[u]) continue;
        if (dist[u] <= dist[v] + e.second) continue;
        if (e.second == B && a[v][u] < INF) continue;
        if (e.second == B && compId[u] != -1) continue;
        dist[u] = dist[v] + e.second;
      }
    }
    for (int v = 0; v < n; v++) dp[v][mask] = dist[v];
    for (int v = 0; v < n; v++)
      for (pair<int, int> e : g[v]) {
        if (e.second != B) continue;
        int u = e.first;
        if (compId[u] == -1) continue;
        if ((mask >> compId[u]) & 1) continue;
        dp[u][mask | (1 << compId[u])] =
            min(dp[u][mask | (1 << compId[u])], dp[v][mask] + e.second);
      }
  }
  for (int v = 0; v < n; v++) {
    int ans = INF;
    for (int mask = 0; mask < (1 << m); mask++) ans = min(ans, dp[v][mask]);
    printf("%d ", ans);
  }
  printf("\n");
  return 0;
}
