#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 75, MAXM = 205;
int n, m, A, B, cnt;
int d[MAXN], id[MAXN], ans[MAXN];
int f[MAXN][(int)2e5], fa[MAXN];
int tot, h[MAXN];
struct edge {
  int to, nxt, val;
} e[MAXM << 2];
void add(int x, int y, int z) {
  e[++tot] = (edge){y, h[x], z};
  h[x] = tot;
}
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
void dfs(int k, int dis, int S) {
  if (dis >= f[k][S]) return;
  f[k][S] = dis, ans[k] = min(f[k][S], ans[k]);
  for (int u = h[k]; u; u = e[u].nxt) {
    if (e[u].val == A)
      dfs(e[u].to, dis + A, S);
    else if (fa[e[u].to] != fa[k] &&
             (id[e[u].to] == -1 || !(S & (1 << id[e[u].to]))))
      dfs(e[u].to, dis + B, (id[k] != -1) ? (S | (1 << id[k])) : S);
  }
}
int main() {
  int i, j, k;
  int x, y, z;
  memset(id, -1, sizeof(id));
  memset(f, 127, sizeof(f));
  memset(ans, 127, sizeof(ans));
  scanf("%d%d%d%d", &n, &m, &A, &B);
  for (i = 1; i <= n; ++i) fa[i] = i;
  for (i = 1; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &z), add(x, y, z), add(y, x, z);
    if (z == A && get(x) != get(y)) fa[get(x)] = get(y);
  }
  for (i = 1; i <= n; ++i) ++d[get(i)];
  for (i = 1; i <= n; ++i)
    if (get(i) == i && d[i] >= 4) id[i] = cnt++;
  for (i = 1; i <= n; ++i) id[i] = id[get(i)];
  dfs(1, 0, 0);
  for (i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
