#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e5 + 107;
const double pi = acos(-1.0);
const double eps = 0.0000000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline void pr2(T x, int k = 64) {
  long long i;
  for (i = 0; i < k; i++) fprintf(stderr, "%d", (x >> i) & 1);
  putchar(' ');
}
template <typename T>
inline void add_(T &A, int B, long long MOD = M) {
  A += B;
  (A >= MOD) && (A -= MOD);
}
template <typename T>
inline void mul_(T &A, long long B, long long MOD = M) {
  A = (A * B) % MOD;
}
template <typename T>
inline void mod_(T &A, long long MOD = M) {
  A %= MOD;
  A += MOD;
  A %= MOD;
}
template <typename T>
inline void max_(T &A, T B) {
  (A < B) && (A = B);
}
template <typename T>
inline void min_(T &A, T B) {
  (A > B) && (A = B);
}
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
inline long long powMM(long long a, long long b, long long mod = M) {
  long long ret = 1;
  for (; b; b >>= 1ll, a = a * a % mod)
    if (b & 1) ret = ret * a % mod;
  return ret;
}
int startTime;
void startTimer() { startTime = clock(); }
void printTimer() {
  fprintf(stderr, "/--- Time: %ld milliseconds ---/\n", clock() - startTime);
}
vector<pair<int, int> > edge[107];
int fa[107], sz[107];
inline int getfa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getfa(fa[x]);
}
long long val[1 << 18][78];
int label[107], id[107];
priority_queue<pair<long long, pair<int, int> > > Q;
int main() {
  int n, m, i, k;
  long long a, b;
  scanf("%d%d%lld%lld", &n, &m, &a, &b);
  for (i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
  for (i = 1; i <= m; i++) {
    int u, v;
    long long c;
    scanf("%d%d%lld", &u, &v, &c);
    edge[u].push_back(make_pair(v, c));
    edge[v].push_back(make_pair(u, c));
    if (c == a) {
      int x = getfa(u), y = getfa(v);
      if (x == y)
        continue;
      else
        fa[x] = y, sz[y] += sz[x];
    }
  }
  int N = 0;
  for (i = 1; i <= n; i++)
    if (getfa(i) == i && sz[i] >= 4) label[i] = N++;
  for (i = 1; i <= n; i++)
    if (sz[getfa(i)] >= 4) id[i] = 1 << label[getfa(i)];
  memset(val, 0x3f, sizeof(val));
  val[id[1]][1] = 0;
  Q.push(make_pair(0, make_pair(id[1], 1)));
  while (Q.size()) {
    pair<long long, pair<int, int> > now = Q.top();
    Q.pop();
    long long len = -now.first;
    int sta = now.second.first, x = now.second.second;
    if (val[sta][x] != len) continue;
    for (pair<int, int> e : edge[x]) {
      int l = e.second, v = e.first;
      if (l == b && ((sta & id[v]) || (getfa(x) == getfa(v)))) continue;
      if (val[sta | id[v]][v] > l + len) {
        val[sta | id[v]][v] = l + len;
        Q.push(make_pair(-l - len, make_pair(sta | id[v], v)));
      }
    }
  }
  for (i = 1; i <= n; i++) {
    long long ans = INFF;
    for (k = 0; k < 1 << N; k++) ans = min(ans, val[k][i]);
    printf("%lld ", ans);
  }
}
