#include <bits/stdc++.h>
using namespace std;
const int maxn = 70, maxm = 200;
int n, m, a, b, m1, m2, fa[maxn + 5], id[maxn + 5], sz[maxn + 5];
int cc, c[maxn + 5], dp[1 << 17][maxn + 5], ans[maxn + 5];
pair<int, int> e1[maxm + 5], e2[maxm + 5];
vector<pair<int, int> > G[maxn + 5];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void dijkstra(int dis[]) {
  priority_queue<pair<int, int> > H;
  for (int i = (1); i <= int(n); i++) {
    H.push({-dis[i], i});
  }
  for (pair<int, int> p; !H.empty();) {
    static int u, v, w;
    p = H.top(), H.pop();
    u = p.second;
    if (-p.first != dis[u]) {
      continue;
    }
    for (pair<int, int> q : G[u]) {
      v = q.first, w = q.second;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        H.push({-dis[v], v});
      }
    }
  }
}
inline void cmin(int &x, int y) { x > y ? x = y : 0; }
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  for (int i = (1); i <= int(m); i++) {
    static int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    if (w == a) {
      e1[++m1] = pair<int, int>(u, v);
    } else {
      e2[++m2] = pair<int, int>(u, v);
    }
  }
  for (int i = (1); i <= int(n); i++) {
    fa[i] = i;
  }
  for (int i = (1); i <= int(m1); i++) {
    fa[find(e1[i].first)] = find(e1[i].second);
  }
  for (int i = (1); i <= int(n); i++) {
    id[i] = -i, sz[find(i)]++;
  }
  for (int i = (1); i <= int(n); i++)
    if (find(i) == i && sz[i] >= 4) {
      id[i] = cc++;
    }
  for (int i = (1); i <= int(n); i++) {
    c[i] = id[find(i)];
  }
  for (int msk = (0); msk <= int((1 << cc) - 1); msk++)
    for (int i = (1); i <= int(n); i++) {
      dp[msk][i] = 1e9;
    }
  for (int i = (1); i <= int(m1); i++) {
    int u = e1[i].first, v = e1[i].second;
    G[u].emplace_back(v, a);
    G[v].emplace_back(u, a);
  }
  for (int i = (1); i <= int(m2); i++) {
    int u = e2[i].first, v = e2[i].second;
    if (c[u] != c[v] && c[v] < 0) {
      G[u].emplace_back(v, b);
    }
    if (c[u] != c[v] && c[u] < 0) {
      G[v].emplace_back(u, b);
    }
  }
  dp[c[1] < 0 ? 0 : 1 << c[1]][1] = 0;
  for (int i = (1); i <= int(n); i++) {
    ans[i] = 1e9;
  }
  for (int msk = (0); msk <= int((1 << cc) - 1); msk++) {
    dijkstra(dp[msk]);
    for (int i = (1); i <= int(n); i++) {
      cmin(ans[i], dp[msk][i]);
    }
    for (int i = (1); i <= int(m2); i++) {
      int u = e2[i].first, v = e2[i].second;
      if (c[u] != c[v] && c[v] >= 0 && ~msk >> c[v] & 1) {
        cmin(dp[msk | (1 << c[v])][v], dp[msk][u] + b);
      }
      if (c[u] != c[v] && c[u] >= 0 && ~msk >> c[u] & 1) {
        cmin(dp[msk | (1 << c[u])][u], dp[msk][v] + b);
      }
    }
  }
  for (int i = (1); i <= int(n); i++) {
    printf("%d%c", ans[i], " \n"[i == n]);
  }
  return 0;
}
