#include <bits/stdc++.h>
const int maxn = 75, maxm = 405;
int head[maxn], next[maxm], w[maxm], to[maxm], lb;
int A, B, n, m, clr[maxn], rot[maxn], siz[maxn], numColor,
    d[maxn][1 << (maxn / 4)];
struct Node {
  Node(int i_ = 0, int s_ = 0, int d_ = 0) : id(i_), state(s_), dis(d_) {}
  bool operator<(const Node& rhs) const { return dis > rhs.dis; }
  int id, state, dis;
};
inline void ist(int aa, int ss, int ww) {
  to[lb] = ss;
  next[lb] = head[aa];
  head[aa] = lb;
  w[lb] = ww;
  ++lb;
}
inline int getState(int r) {
  if (clr[r] == -1) {
    return 0;
  }
  return 1 << clr[r];
}
int que[maxn];
inline void bfs(int start) {
  int head_, tail, h;
  head_ = tail = 0;
  que[tail++] = start;
  while (head_ != tail) {
    h = que[head_++];
    rot[h] = start;
    for (int j = head[h]; j != -1; j = next[j]) {
      if (rot[to[j]]) {
        continue;
      }
      if (w[j] == B) {
        continue;
      }
      que[tail++] = to[j];
    }
  }
  siz[start] = tail;
}
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d%d%d", &n, &m, &A, &B);
  int t1, t2, t3;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &t1, &t2, &t3);
    ist(t1, t2, t3);
    ist(t2, t1, t3);
  }
  for (int i = 1; i <= n; ++i) {
    if (!rot[i]) {
      bfs(i);
    }
  }
  memset(clr, -1, sizeof clr);
  for (int i = 1; i <= n; ++i) {
    int r = rot[i];
    if (siz[r] < 4) {
      continue;
    }
    if (clr[r] == -1) {
      clr[r] = numColor++;
    }
    clr[i] = clr[r];
  }
  memset(d, 0x3c, sizeof d);
  std::priority_queue<Node> hp;
  d[1][getState(1)] = 0;
  hp.push(Node(1, getState(1), 0));
  Node h;
  while (!hp.empty()) {
    h = hp.top();
    hp.pop();
    if (d[h.id][h.state] < h.dis) {
      continue;
    }
    for (int j = head[h.id]; j != -1; j = next[j]) {
      if (w[j] == B) {
        if (clr[to[j]] != -1 && (h.state >> clr[to[j]] & 1)) {
          continue;
        }
        if (rot[to[j]] == rot[h.id]) {
          continue;
        }
      }
      int& rd = d[to[j]][h.state | getState(to[j])];
      if (rd > h.dis + w[j]) {
        rd = h.dis + w[j];
        hp.push(Node(to[j], h.state | getState(to[j]), rd));
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    int mn = *std::min_element(d[i], d[i] + (1 << numColor));
    printf("%d%c", mn, i == n ? '\n' : ' ');
  }
  return 0;
}
