#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool t = false;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = true, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return t ? -x : x;
}
struct Line {
  int v, next, w;
} e[500];
int h[72], cnt = 1;
inline void Add(int u, int v, int w) {
  e[cnt] = (Line){v, h[u], w};
  h[u] = cnt++;
}
int f[72], sz[72];
int getf(int x) { return x == f[x] ? x : f[x] = getf(f[x]); }
void Merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  f[y] = x;
  sz[x] += sz[y];
}
int dis[72][131072];
bool vis[72][131072];
struct Node {
  int u, d, S;
};
bool operator<(Node a, Node b) { return a.d > b.d; }
priority_queue<Node> Q;
void upd(int u, int d, int S) {
  if (dis[u][S] > d) dis[u][S] = d, Q.push((Node){u, d, S});
}
int n, m, A, B, book[72], tim;
int main() {
  n = read();
  m = read();
  A = read();
  B = read();
  for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1, book[i] = -1;
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read(), w = read();
    Add(u, v, w);
    Add(v, u, w);
    if (w == A) Merge(u, v);
  }
  for (int i = 1; i <= n; ++i)
    if (book[i] == -1 && sz[getf(i)] > 3) {
      for (int j = i; j <= n; ++j)
        if (getf(i) == getf(j)) book[j] = tim;
      ++tim;
    }
  memset(dis, 63, sizeof(dis));
  upd(1, 0, (~book[1]) ? 1 << book[1] : 0);
  while (!Q.empty()) {
    Node a = Q.top();
    Q.pop();
    int u = a.u, d = a.d, S = a.S;
    if (vis[u][S]) continue;
    vis[u][S] = true;
    for (int i = h[u]; i; i = e[i].next) {
      int v = e[i].v, w = e[i].w;
      if (w == A)
        upd(v, dis[u][S] + w, S);
      else {
        if (getf(u) == getf(v)) continue;
        if (~book[v] && (S & (1 << book[v]))) continue;
        upd(v, dis[u][S] + w, S | ((~book[v]) ? 1 << book[v] : 0));
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    int ans = 1 << 30;
    for (int j = 0; j < 1 << tim; ++j) ans = min(ans, dis[i][j]);
    printf("%d ", ans);
  }
  return 0;
}
