#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int N = 80;
int n, m, a, b, w[N][N], p[N], pp[N];
int fa[N], sz[N];
int ask(int x) { return fa[x] == x ? x : fa[x] = ask(fa[x]); }
void link(int x, int y) {
  x = ask(x);
  y = ask(y);
  if (x != y) fa[y] = x, sz[x] += sz[y], sz[y] = 0;
}
long long dis[N][1 << 17];
bool vis[N][1 << 17];
long long ans[N];
queue<pair<int, int> > q, q2;
void upd(long long& a, long long b) {
  if (b < a) a = b;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
  for (int i = 1; i <= m; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    w[v][u] = w[u][v] = c;
    if (c == a) link(u, v);
  }
  for (int i = 1; i <= n; ++i) fa[i] = ask(i);
  for (int i = 1; i <= n; ++i)
    if (fa[i] == i && sz[i] >= 4) p[i] = ++p[0], pp[p[0]] = p[i];
  for (int i = 1; i <= n; ++i) ans[i] = inf;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= (1 << 17) - 1; ++j) dis[i][j] = inf;
  dis[1][0] = 0;
  q.push(make_pair(1, 0));
  while (!q.empty() || !q2.empty()) {
    pair<int, int> u;
    if (q.empty())
      u = q2.front(), q2.pop();
    else if (q2.empty())
      u = q.front(), q.pop();
    else {
      pair<int, int> u1 = q.front(), u2 = q2.front();
      if (dis[u1.first][u1.second] < dis[u2.first][u2.second])
        u = u1, q.pop();
      else
        u = u2, q2.pop();
    }
    if (vis[u.first][u.second]) continue;
    vis[u.first][u.second] = 1;
    long long d = dis[u.first][u.second];
    upd(ans[u.first], d);
    for (int i = 1; i <= n; ++i)
      if (w[u.first][i]) {
        if (w[u.first][i] == b && fa[u.first] == fa[i]) continue;
        pair<int, int> v = make_pair(i, u.second);
        if (p[fa[u.first]] && w[u.first][i] == b)
          v.second |= (1 << p[fa[u.first]] - 1);
        if (p[fa[i]] && (v.second & (1 << p[fa[i]] - 1))) continue;
        if (w[u.first][i] == a)
          q.push(v), upd(dis[v.first][v.second], d + a);
        else
          q2.push(v), upd(dis[v.first][v.second], d + b);
      }
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", ans[i]);
  puts("");
}
