#include <bits/stdc++.h>
using namespace std;
const int maxn = 73, MASK = (1 << 17) + 10, inf = 1e9;
int pr[maxn], id[maxn], ds[maxn][MASK];
bool is[maxn][MASK];
vector<pair<int, int> > v[maxn];
int Find(int u) { return pr[u] < 0 ? u : pr[u] = Find(pr[u]); }
void Merge(int a, int b) {
  if ((a = Find(a)) == (b = Find(b))) return;
  if (pr[a] > pr[b]) swap(a, b);
  pr[a] += pr[b];
  pr[b] = a;
}
vector<pair<int, int> > ed;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(pr, -1, sizeof pr);
  int n, m, A, B;
  cin >> n >> m >> A >> B;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    if (c == A) {
      Merge(a, b);
      v[a].push_back({b, c});
      v[b].push_back({a, c});
    } else {
      ed.push_back({a, b});
    }
  }
  for (pair<int, int> p : ed) {
    if (Find(p.first) != Find(p.second))
      v[p.first].push_back({p.second, B}), v[p.second].push_back({p.first, B});
  }
  memset(id, -1, sizeof id);
  int C = 0;
  for (int i = 0; i < n; i++) {
    if (-pr[Find(i)] > 3) {
      if (id[Find(i)] == -1) id[Find(i)] = C++;
      id[i] = id[Find(i)];
    }
  }
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      pq;
  memset(ds, 127, sizeof ds), ds[0][id[0] == -1 ? 0 : (1 << id[0])] = 0;
  pq.push({0, {0, id[0] == -1 ? 0 : (1 << id[0])}});
  while (int((pq).size())) {
    pair<int, int> u = pq.top().second;
    pq.pop();
    if (is[u.first][u.second]) continue;
    is[u.first][u.second] = 1;
    for (pair<int, int> p : v[u.first]) {
      if (id[p.first] != -1 && (((u.second) >> (id[p.first])) & 1) &&
          id[u.first] != id[p.first])
        continue;
      int w = ds[u.first][u.second] + p.second,
          msk = u.second | (id[p.first] == -1 ? 0 : (1 << id[p.first]));
      if (w < ds[p.first][msk])
        ds[p.first][msk] = w, pq.push({w, {p.first, msk}});
    }
  }
  for (int i = 0; i < n; i++) {
    int ans = inf;
    for (int j = 0; j < (1 << C); j++) {
      ans = min(ans, ds[i][j]);
    }
    cout << ans << " ";
  }
  return cout << endl, 0;
}
