#include <bits/stdc++.h>
using namespace std;
int n, m, A, B, f[75], siz[75], id[75], tim, dis[1 << 18][75];
int fir[75], nxt[405], to[405], w[405], tot;
inline void line(int x, int y, int z) {
  nxt[++tot] = fir[x];
  fir[x] = tot;
  to[tot] = y;
  w[tot] = z;
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
struct node {
  int s, p;
};
queue<node> q;
bool inq[1 << 18][75];
inline bool chkmin(int &a, int b) { return a > b ? (a = b, 1) : 0; }
int main() {
  scanf("%d%d%d%d", &n, &m, &A, &B);
  for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    line(x, y, z), line(y, x, z);
    if (z == A) {
      if ((x = find(x)) != (y = find(y))) f[x] = y, siz[y] += siz[x];
    }
  }
  for (int i = 1; i <= n; i++)
    if (f[i] == i && siz[i] > 3) {
      for (int j = 1; j <= n; j++)
        if (find(j) == i) id[j] = 1 << tim;
      tim++;
    }
  memset(dis, 0x3f, sizeof dis);
  dis[id[1]][1] = 0;
  q.push((node){id[1], 1});
  while (!q.empty()) {
    int s = q.front().s, u = q.front().p;
    q.pop(), inq[s][u] = 0;
    for (int i = fir[u], v; i; i = nxt[i]) {
      v = to[i];
      if (w[i] == A) {
        if (chkmin(dis[s][v], dis[s][u] + w[i]) && !inq[s][v])
          inq[s][v] = 1, q.push((node){s, v});
      } else if (find(u) != find(v) && !(s & id[v])) {
        if (chkmin(dis[s | id[v]][v], dis[s][u] + w[i]) && !inq[s | id[v]][v])
          inq[s | id[v]][v] = 1, q.push((node){s | id[v], v});
      }
    }
  }
  putchar('0');
  for (int i = 2, x; i <= n; i++) {
    x = 0x3f3f3f3f;
    for (int s = 0; s < 1 << tim; s++) x = min(x, dis[s][i]);
    printf(" %d", x);
  }
}
