#include <bits/stdc++.h>
using namespace std;
const int nmax = 80;
struct node {
  int co, nd, stare;
};
bool operator<(node unu, node doi) { return (unu.co > doi.co); }
vector<pair<int, int> > v[nmax];
int viz[nmax], co[nmax], st[nmax], act[nmax];
int dp[nmax][(1 << 17) + 5];
int A, B, n, i, m, compo, j, dist, nod, cost, x, y, c, u, cate;
priority_queue<node> pq;
void dfs(int x) {
  viz[x] = 1;
  st[++u] = x;
  act[x] = cate;
  for (int i = 0; i < v[x].size(); i++)
    if ((!viz[v[x][i].first]) && v[x][i].second == A) dfs(v[x][i].first);
}
void prp(int N, int S, int val) {
  if (val < dp[N][S]) {
    dp[N][S] = val;
    pq.push({val, N, S});
  }
}
void dij() {
  int state = 0;
  if (co[1] != -1) state = (1 << (co[1]));
  for (int i = 1; i <= n; i++) {
    for (j = 0; j < (1 << compo); j++) dp[i][j] = (int)2 * 1e9;
  }
  dp[1][state] = 0;
  pq.push({0, 1, state});
  while (!pq.empty()) {
    x = pq.top().nd;
    state = pq.top().stare;
    dist = pq.top().co;
    pq.pop();
    if (dist == dp[x][state]) {
      for (i = 0; i < v[x].size(); i++) {
        nod = v[x][i].first;
        cost = v[x][i].second;
        if (cost == A) {
          prp(nod, state, dist + cost);
        } else if (act[x] != act[nod]) {
          if (co[nod] == -1)
            prp(nod, state, dist + cost);
          else {
            if (!(state & (1 << co[nod])))
              prp(nod, (state | (1 << co[nod])), dist + cost);
          }
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> A >> B;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> c;
    v[x].push_back({y, c});
    v[y].push_back({x, c});
  }
  for (int i = 1; i <= n; i++) co[i] = -1;
  for (int i = 1; i <= n; i++)
    if (!viz[i]) {
      u = 0;
      ++cate;
      dfs(i);
      if (u > 3) {
        compo++;
        for (int j = 1; j <= u; j++) co[st[j]] = compo - 1;
      }
    }
  dij();
  for (i = 1; i <= n; i++) {
    int ans = (int)2 * 1e9;
    for (j = 0; j < (1 << compo); j++) ans = min(ans, dp[i][j]);
    cout << ans << ' ';
  }
  return 0;
}
