#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 70, M = 202;
int fa[N], siz[N];
inline int Find(int x) { return x == fa[x] ? x : (fa[x] = Find(fa[x])); }
inline void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  if (x == y) return;
  fa[x] = y, siz[y] += siz[x];
}
const int S = 1 << 19, V = S * 70, INF = 2e9;
int dis[V], ans[N];
int cntid, id[N], cntv;
inline int code(int x, int s) { return (x << cntid) | s; }
inline void decode(int id, int &x, int &s) {
  x = id >> cntid, s = id & ((1 << cntid) - 1);
}
queue<int> qA, qB;
int n, m, A, B, ex[M], ey[M], ez[M];
vector<int> GA[N], GB[N];
int main() {
  int i, j;
  cin >> n >> m >> A >> B;
  for (i = 0; i < n; ++i) fa[i] = i, siz[i] = 1, ans[i] = INF;
  for (i = 1; i <= m; ++i) {
    cin >> ex[i] >> ey[i] >> ez[i], --ex[i], --ey[i];
    if (ez[i] == A)
      Merge(ex[i], ey[i]), GA[ex[i]].push_back(i), GA[ey[i]].push_back(i);
    else
      GB[ex[i]].push_back(i), GB[ey[i]].push_back(i);
  }
  for (i = 0; i < n; ++i) fa[i] = Find(i), id[i] = -1;
  for (i = 0; i < n; ++i)
    if (i == fa[i] && siz[i] >= 4) id[i] = cntid++;
  for (i = 0; i < n; ++i) id[i] = id[fa[i]];
  for (i = 0; i < n; ++i) id[i] = id[i] == -1 ? 0 : (1 << id[i]);
  cntv = n * (1 << cntid);
  int x, y, e, s, now, tmp = id[0];
  for (i = 0; i < cntv; ++i) dis[i] = INF;
  dis[tmp] = 0, qA.push(tmp);
  while (!(qA.empty() && qB.empty())) {
    if (qA.empty())
      tmp = qB.front(), qB.pop();
    else if (qB.empty())
      tmp = qA.front(), qA.pop();
    else if (dis[qA.front()] < dis[qB.front()])
      tmp = qA.front(), qA.pop();
    else
      tmp = qB.front(), qB.pop();
    decode(tmp, x, s), now = tmp;
    for (i = 0; i < GA[x].size(); ++i) {
      e = GA[x][i], y = ex[e] + ey[e] - x, tmp = (y << cntid) | s | id[y];
      if (dis[tmp] > dis[now] + A) dis[tmp] = dis[now] + A, qA.push(tmp);
    }
    for (i = 0; i < GB[x].size(); ++i) {
      e = GB[x][i], y = ex[e] + ey[e] - x;
      if (!(id[y] & s) && fa[y] != fa[x]) {
        tmp = (y << cntid) | s | id[y];
        if (dis[tmp] > dis[now] + B) dis[tmp] = dis[now] + B, qB.push(tmp);
      }
    }
  }
  for (i = 0; i < cntv; ++i)
    if (dis[i] < INF) ans[i >> cntid] = min(ans[i >> cntid], dis[i]);
  for (i = 0; i < n; ++i) write(ans[i]), putchar(i < n - 1 ? ' ' : '\n');
  return 0;
}
