#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
vector<int> reb1[arr];
vector<int> reb2[arr];
bool use[arr];
int comp[arr];
const int M = 70 / 4 + 1;
int dist[1ll << M][71];
void dfs(int now, int c) {
  comp[now] = c;
  use[now] = 1;
  for (auto wh : reb1[now]) {
    if (!use[wh]) {
      dfs(wh, c);
    }
  }
}
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    if (c == a) {
      reb1[u].push_back(v);
      reb1[v].push_back(u);
    }
    if (c == b) {
      reb2[u].push_back(v);
      reb2[v].push_back(u);
    }
  }
  int c = 0;
  int cc = 1e5;
  for (int i = 1; i <= n; i++) {
    if (!use[i]) {
      dfs(i, ++c);
      int cnt = 0;
      for (int j = 1; j <= n; j++) {
        if (comp[j] == c) {
          cnt++;
        }
      }
      if (cnt <= 3) {
        for (int j = 1; j <= n; j++) {
          if (comp[j] == c) {
            comp[j] = cc;
          }
        }
        cc--;
        c--;
      }
    }
  }
  set<pair<int, pair<int, int>>> s;
  int start_mask = 0;
  if (comp[1] <= c) {
    start_mask |= (1ll << (comp[1] - 1));
  }
  for (int m = 0; m < (1ll << c); m++) {
    for (int j = 1; j <= n; j++) {
      if (j == 1 && m == start_mask) {
        dist[m][j] = 0;
      } else {
        dist[m][j] = 2e9 + 1;
      }
      s.insert(make_pair(dist[m][j], make_pair(m, j)));
    }
  }
  function<bool(int, int)> have_bit = [&](int m, int bit) {
    return m & (1ll << bit);
  };
  while (!s.empty()) {
    pair<int, int> now = s.begin()->second;
    s.erase(s.begin());
    for (auto wh : reb1[now.second]) {
      if (comp[wh] > c || comp[now.second] == comp[wh] ||
          !have_bit(now.first, comp[wh] - 1)) {
        int to_m = now.first | (comp[wh] > c ? 0 : (1ll << (comp[wh] - 1)));
        if (dist[to_m][wh] > dist[now.first][now.second] + a) {
          s.erase(make_pair(dist[to_m][wh], make_pair(to_m, wh)));
          dist[to_m][wh] = dist[now.first][now.second] + a;
          s.insert(make_pair(dist[to_m][wh], make_pair(to_m, wh)));
        }
      }
    }
    for (auto wh : reb2[now.second]) {
      if ((comp[wh] > c || !have_bit(now.first, comp[wh] - 1)) &&
          (comp[wh] != comp[now.second])) {
        int to_m = now.first | (comp[wh] > c ? 0 : (1ll << (comp[wh] - 1)));
        if (dist[to_m][wh] > dist[now.first][now.second] + b) {
          s.erase(make_pair(dist[to_m][wh], make_pair(to_m, wh)));
          dist[to_m][wh] = dist[now.first][now.second] + b;
          s.insert(make_pair(dist[to_m][wh], make_pair(to_m, wh)));
        }
      }
    }
  }
  for (int j = 1; j <= n; j++) {
    int ans = 2e9 + 1;
    for (int m = 0; m < (1ll << c); m++) {
      ans = min(ans, dist[m][j]);
    }
    cout << ans << " ";
  }
  cout << "\n";
}
