#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
}
using namespace std;
const int base = 17;
const int mask = (1 << 17) - 1;
const int inf = 2e9 + 100;
template <typename T>
inline void MIN(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void MAX(T &a, T b) {
  if (a < b) a = b;
}
int n, m, a, b;
struct Edge {
  int u, v, w;
  Edge() {}
  Edge(int jzp, int zzz, int lsr) {
    u = jzp;
    v = zzz;
    w = lsr;
  }
} E[222];
int fath[77];
int find(int cur) {
  return fath[cur] == cur ? cur : fath[cur] = find(fath[cur]);
}
int col[77], ctot, csiz[77];
struct edge {
  int nxt, to, val;
  edge() {}
  edge(int jzp, int zzz, int lsr) {
    nxt = jzp;
    to = zzz;
    val = lsr;
  }
} e[222 << 1];
int head[77], ecnt;
inline void addedge(int from, int to, int val) {
  e[++ecnt] = (edge){head[from], to, val};
  head[from] = ecnt;
}
int que[20001000], front, rear;
int dis[77 * 141000];
bool vis[77 * 141000];
inline int F(int x, int y) { return (x << base) | y; }
inline void spfa() {
  for (int i = 1; i <= n; ++i) {
    int All = (1 << ctot) - 1;
    for (int s = 0; s <= All; ++s) dis[F(i, s)] = inf;
  }
  dis[F(1, ~col[1] ? 1 << col[1] : 0)] = 0;
  que[++rear] = F(1, ~col[1] ? 1 << col[1] : 0);
  while (front < rear) {
    int nws = que[++front];
    int cur = nws >> base, s = nws & mask;
    vis[nws] = false;
    for (int i = head[cur]; i; i = e[i].nxt) {
      int to = e[i].to;
      if (~col[to] && col[to] != col[cur] && (s & (1 << col[to]))) continue;
      int tos = F(to, ~col[to] ? s | (1 << col[to]) : s);
      if (dis[tos] <= dis[nws] + e[i].val) continue;
      dis[tos] = dis[nws] + e[i].val;
      if (!vis[tos]) que[++rear] = tos;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int res = inf, All = (1 << ctot) - 1;
    for (int s = 0; s <= All; ++s) MIN(res, dis[F(i, s)]);
    printf("%d ", res);
  }
  puts("");
}
int main() {
  read(n), read(m), read(a), read(b);
  for (int i = 1; i <= n; ++i) fath[i] = i;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    read(u), read(v), read(w);
    if (w == a) {
      int fu = find(u), fv = find(v);
      if (fu != fv) fath[fu] = fv;
    }
    E[i] = Edge(u, v, w);
  }
  for (int i = 1; i <= n; ++i) ++csiz[find(i)];
  for (int i = 1; i <= n; ++i)
    if (fath[i] == i) {
      if (csiz[i] > 3)
        col[i] = ctot++;
      else
        col[i] = -1;
    }
  for (int i = 1; i <= n; ++i) col[i] = col[find(i)];
  for (int i = 1; i <= m; ++i) {
    int u = E[i].u, v = E[i].v, w = E[i].w;
    if (w == a)
      addedge(u, v, w), addedge(v, u, w);
    else if (find(u) != find(v))
      addedge(u, v, w), addedge(v, u, w);
  }
  spfa();
  return 0;
}
