#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
vector<pair<int, int>> mp[135];
int A, B, C;
int col[135], be[135], zi;
bool vis[135];
vector<int> vpt;
void dfs(int x) {
  vis[x] = 1;
  vpt.push_back(x);
  be[x] = zi;
  for (auto cp : mp[x])
    if (!vis[cp.first] && cp.second == A) {
      dfs(cp.first);
    }
}
int dis[(1 << 17) + 2][72], Ans[72];
bool used[(1 << 17) + 2][72];
void dij() {
  for (int(i) = 0; (i) < (int)(1 << C); (i)++)
    for (int(x) = 1; (x) <= (int)(n); (x)++) dis[i][x] = (1000000000);
  int bs = 0;
  dis[bs][1] = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) Ans[i] = (1000000000);
  Ans[1] = 0;
  priority_queue<pair<int, pair<int, int>>,
                 std::vector<pair<int, pair<int, int>>>,
                 std::greater<pair<int, pair<int, int>>>>
      q;
  q.push({0, {bs, 1}});
  while (!q.empty()) {
    pair<int, int> sta = q.top().second;
    q.pop();
    int x = sta.second;
    if (used[sta.first][x]) continue;
    used[sta.first][x] = 1;
    int msk = sta.first;
    for (auto cp : mp[x]) {
      int d = cp.second, y = cp.first;
      int nk = msk;
      if (d == B && be[x] == be[y]) continue;
      if (col[x] != col[y]) {
        if (col[y] == -1) {
          if (col[x] != -1) nk |= 1 << col[x];
        } else {
          if ((msk & (1 << col[y])) != 0) continue;
          if (col[x] != -1) nk |= 1 << col[x];
        }
      }
      if (dis[msk][x] + d < dis[nk][y]) {
        dis[nk][y] = dis[msk][x] + d;
        mintt(Ans[y], dis[nk][y]);
        q.push({dis[nk][y], {nk, y}});
      }
    }
  }
}
void fmain(int tid) {
  scanf("%d%d%d%d", &n, &m, &A, &B);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    mp[u].push_back({v, c});
    mp[v].push_back({u, c});
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) col[i] = -1;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (!vis[i]) {
      zi++;
      vpt.clear();
      dfs(i);
      if (vpt.size() > 3) {
        for (int z : vpt) col[z] = C;
        C++;
      }
    }
  dij();
  for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d ", Ans[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
