#include <bits/stdc++.h>
using namespace std;
const int N = 71, M = (1 << 17), inf = 2e9;
int n, m, a, b;
vector<int> G_in[N], G_out[N];
void add_edge(vector<int> G[], int u, int v) {
  G[u].emplace_back(v);
  G[v].emplace_back(u);
}
void read() {
  cin >> n >> m >> a >> b;
  for (int i = 1, u, v, c; i <= m; i++) {
    cin >> u >> v >> c;
    if (c == a)
      add_edge(G_in, u, v);
    else
      add_edge(G_out, u, v);
  }
}
int belong[N], id[N], cnt = 0, sl = 0, sz[N], d[N][M];
void dfs(int u, int r) {
  belong[u] = r;
  sz[r]++;
  for (int v : G_in[u])
    if (!belong[v]) dfs(v, r);
}
void process() {
  for (int i = 1; i <= n; i++)
    if (!belong[i]) {
      dfs(i, ++cnt);
      if (sz[cnt] >= 4) id[cnt] = ++sl;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (1 << sl); j++) d[i][j] = inf;
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                 greater<pair<int, pair<int, int>>>>
      q;
  if (id[belong[1]])
    d[1][1 << (id[belong[1]] - 1)] = 0,
                               q.push(make_pair(
                                   0, make_pair(1, 1 << (id[belong[1]] - 1))));
  else
    d[1][0] = 0, q.push(make_pair(0, make_pair(1, 0)));
  while (!q.empty()) {
    int u = q.top().second.first, mask = q.top().second.second,
        w = q.top().first;
    q.pop();
    for (int v : G_in[u])
      if (w + a < d[v][mask])
        d[v][mask] = w + a, q.push(make_pair(w + a, make_pair(v, mask)));
    for (int v : G_out[u])
      if (belong[v] != belong[u]) {
        int nmask = mask, t = id[belong[v]];
        if (t) {
          if ((mask >> (t - 1)) & 1) continue;
          nmask |= 1 << (t - 1);
        }
        if (w + b < d[v][nmask])
          d[v][nmask] = w + b, q.push(make_pair(w + b, make_pair(v, nmask)));
      }
    while (!q.empty() &&
           d[q.top().second.first][q.top().second.second] < q.top().first)
      q.pop();
  }
  for (int i = 1; i <= n; i++) {
    int res = inf;
    for (int j = 0; j < (1 << sl); j++) res = min(res, d[i][j]);
    cout << res << " ";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  read();
  process();
  return 0;
}
