#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 75;
const int B = N / 4;
int n, a, b, d[N][N];
int ncomp = 0, sz[N], which[N];
int nbit, bit[N];
vector<int> adj[N];
int dist[1 << B][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> m >> a >> b;
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(n); j++) d[i][j] = INF;
    d[i][i] = 0;
  }
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    if (c == a) d[u][v] = d[v][u] = a;
    if (c == b) adj[u].push_back(v);
  }
  for (int k = 0; k < (int)(n); k++)
    for (int i = 0; i < (int)(n); i++)
      for (int j = 0; j < (int)(n); j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  fill_n(which, n, -1);
  fill_n(bit, n, (-1));
  for (int i = 0; i < (int)(n); i++)
    if (which[i] == -1) {
      int cur = ncomp++;
      for (int j = 0; j < (int)(n); j++)
        if (d[i][j] < INF) {
          which[j] = cur;
          sz[cur]++;
        }
      if (sz[cur] >= 4) bit[cur] = nbit++;
    }
  for (int u = 0; u < (int)(n); u++)
    for (auto v : adj[u])
      if (d[u][v] == INF) {
        d[u][v] = d[v][u] = b;
      }
  priority_queue<tuple<int, int, int>> q;
  int zeroMask = bit[which[0]] == (-1) ? 0 : 1 << bit[which[0]];
  q.emplace(0, zeroMask, 0);
  for (int mask = 0; mask < (int)(1 << nbit); mask++)
    for (int u = 0; u < (int)(n); u++) dist[mask][u] = INF;
  dist[zeroMask][0] = 0;
  vector<int> ans(n, INF);
  while (!q.empty()) {
    int d, mask, u;
    tie(d, mask, u) = q.top();
    d = -d;
    q.pop();
    if (d > dist[mask][u]) continue;
    ans[u] = min(ans[u], dist[mask][u]);
    for (int v = 0; v < (int)(n); v++)
      if (::d[u][v] < INF) {
        int nd = d + ::d[u][v];
        int nmask = mask;
        int b = bit[which[v]];
        if (b != (-1)) {
          if (((mask >> b) & 1) && ::d[u][v] > a)
            continue;
          else
            nmask |= 1 << b;
        }
        if (nd < dist[nmask][v]) {
          dist[nmask][v] = nd;
          q.emplace(-nd, nmask, v);
        }
      }
  }
  for (auto x : ans) cout << x << ' ';
  return 0;
}
