#include <bits/stdc++.h>
using namespace std;
const int mn = 75;
const int mm = 255;
int n, m, a, b;
int f[mn];
int sf(int x) { return f[x] == x ? x : f[x] = sf(f[x]); }
struct edge {
  int u, v;
  long long w;
  int to(int x) { return x == u ? v : u; }
  bool has(int x) { return x == v || x == u; }
  bool operator<(const edge &p) const { return w < p.w; }
} e[mm];
struct node {
  int id;
  int S;
  int dist;
  bool operator<(const node &p) const { return dist > p.dist; }
};
int d[1 << 17 | 50][mn];
int needb;
int cnt[mn];
int id[mn], idc;
int ans[mn];
void dijk() {
  queue<node> qa;
  queue<node> qb;
  memset(d, 0x3f, sizeof d);
  int id1 = 1 << id[sf(1)];
  if (id1 < 0) id1 = 0;
  qa.push({1, id1, d[id1][1] = 0});
  while (!qa.empty() || !qb.empty()) {
    node u;
    if (qa.empty())
      u = qb.front(), qb.pop();
    else if (qb.empty())
      u = qa.front(), qa.pop();
    else {
      if (qa.front().dist > qb.front().dist)
        u = qb.front(), qb.pop();
      else
        u = qa.front(), qa.pop();
    }
    if (d[u.S][u.id] < u.dist) continue;
    ans[u.id] = min(ans[u.id], u.dist);
    for (int i = 1; i <= m; i++) {
      if (e[i].w == -1 || !e[i].has(u.id)) continue;
      int nxt = e[i].to(u.id);
      if (e[i].w == a) {
        if (d[u.S][nxt] > d[u.S][u.id] + a) {
          d[u.S][nxt] = d[u.S][u.id] + a;
          qa.push({nxt, u.S, d[u.S][nxt]});
        }
      } else if (id[sf(nxt)] == -1 || (u.S & (1 << id[sf(nxt)])) == 0) {
        int nxtS = u.S | (1 << id[sf(nxt)]);
        if (id[sf(nxt)] == -1) nxtS = u.S;
        if (d[nxtS][nxt] > d[u.S][u.id] + b) {
          d[nxtS][nxt] = d[u.S][u.id] + b;
          qb.push({nxt, nxtS, d[nxtS][nxt]});
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    ans[i] = INT_MAX;
  }
  for (int i = 1; i <= m; i++) scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    if (e[i].w == a && sf(e[i].u) != sf(e[i].v)) {
      f[sf(e[i].u)] = sf(e[i].v);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (e[i].w == b && sf(e[i].u) == sf(e[i].v)) e[i].w = -1;
  }
  for (int i = 1; i <= n; i++) {
    cnt[sf(i)]++;
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] > 3)
      id[i] = idc++;
    else
      id[i] = -1;
  }
  dijk();
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
