#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int x = 0, f = 1;
  register char ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = nc();
  return x * f;
}
inline void write(register int x) {
  if (!x) putchar('0');
  if (x < 0) x = -x, putchar('-');
  static int sta[20];
  register int tot = 0;
  while (x) sta[tot++] = x % 10, x /= 10;
  while (tot) putchar(sta[--tot] + 48);
}
int n, m, a, b, cnt, mx;
int w[75][75], vis[75], lab[75], dis[20000005];
queue<int> q1, q2;
inline int get(register int x) {
  int res = 1;
  vis[x] = 1;
  for (register int i = 1; i <= n; ++i)
    if (w[x][i] == a && !vis[i]) res += get(i);
  return res;
}
inline void dfs(register int x, register int idx) {
  lab[x] = idx;
  for (register int i = 1; i <= n; ++i)
    if (w[x][i] == a && !lab[i]) dfs(i, idx);
}
inline int getsta(register int a, register int b) { return a * n + b - 1; }
int main() {
  n = read(), m = read(), a = read(), b = read();
  for (register int i = 1; i <= m; ++i) {
    int u = read(), v = read(), val = read();
    w[u][v] = w[v][u] = val;
  }
  for (register int i = 1; i <= n; ++i)
    if (!vis[i] && get(i) > 3) dfs(i, ++cnt);
  mx = cnt;
  for (register int i = 1; i <= n; ++i)
    if (!lab[i]) dfs(i, ++cnt);
  memset(dis, 0x3f, sizeof(dis));
  dis[getsta(0, 1)] = 0;
  q1.push(getsta(0, 1)), q2.push(getsta(0, 1));
  while (!q1.empty() || !q2.empty()) {
    int u;
    if (q1.empty())
      u = q2.front(), q2.pop();
    else if (q2.empty())
      u = q1.front(), q1.pop();
    else if (dis[q1.front()] < dis[q2.front()])
      u = q1.front(), q1.pop();
    else
      u = q2.front(), q2.pop();
    int msk = u / n, x = u % n + 1, v;
    for (register int i = 1; i <= n; ++i) {
      if (!w[x][i] || (lab[x] == lab[i] && w[x][i] != a) ||
          (lab[i] <= mx && (msk & (1 << (lab[i] - 1)))))
        continue;
      if (lab[x] <= mx && lab[x] != lab[i])
        v = getsta(msk | (1 << (lab[x] - 1)), i);
      else
        v = getsta(msk, i);
      if (dis[v] > dis[u] + w[x][i]) {
        dis[v] = dis[u] + w[x][i];
        if (w[x][i] == a)
          q1.push(v);
        else
          q2.push(v);
      }
    }
  }
  for (register int i = 1; i <= n; ++i) {
    int ans = 1145141919;
    for (register int msk = 0; msk < 1 << mx; ++msk)
      ans = min(ans, dis[getsta(msk, i)]);
    write(ans), putchar(' ');
  }
  return 0;
}
