#include <bits/stdc++.h>
using namespace std;
const int maxn = 75;
const int INF = 0x3f3f3f3f;
int n, m, a, b;
vector<int> G[maxn];
vector<pair<int, int> > V[maxn];
int vis[maxn];
int dis[(1 << 17) + 5][maxn];
int VIS[(1 << 17) + 5][maxn];
int belong[maxn];
int cnt;
vector<int> same[maxn];
bool cmp(vector<int> a, vector<int> b) { return a.size() > b.size(); }
void dfs(int u, int fa) {
  same[cnt].push_back(u);
  vis[u] = 1;
  for (auto v : G[u]) {
    if (v == fa || vis[v]) continue;
    dfs(v, u);
  }
}
struct HeapNode {
  int S, u, d;
  bool operator<(const HeapNode &rhs) const { return d > rhs.d; }
};
void Dijkstra(int s) {
  priority_queue<HeapNode> Q;
  for (int j = 0; j < (1 << 17); j++)
    for (int i = 1; i <= n; i++) dis[j][i] = INF;
  dis[0][s] = 0;
  Q.push(HeapNode{0, s, 0});
  while (!Q.empty()) {
    HeapNode tmp = Q.top();
    Q.pop();
    if (VIS[tmp.S][tmp.u]) continue;
    VIS[tmp.S][tmp.u] = 1;
    for (auto now : V[tmp.u]) {
      if (belong[now.first] <= 17 && (1 << (belong[now.first] - 1)) & tmp.S)
        continue;
      if (now.second == b && belong[now.first] == belong[tmp.u]) continue;
      if (belong[tmp.u] != belong[now.first] &&
          same[belong[tmp.u]].size() >= 4) {
        if (dis[tmp.S | (1 << (belong[tmp.u] - 1))][now.first] >
            dis[tmp.S][tmp.u] + now.second) {
          dis[tmp.S | (1 << (belong[tmp.u] - 1))][now.first] =
              dis[tmp.S][tmp.u] + now.second;
          Q.push(HeapNode{tmp.S | (1 << (belong[tmp.u] - 1)), now.first,
                          tmp.d + now.second});
        }
      } else {
        if (dis[tmp.S][now.first] > dis[tmp.S][tmp.u] + now.second) {
          dis[tmp.S][now.first] = dis[tmp.S][tmp.u] + now.second;
          Q.push(HeapNode{tmp.S, now.first, tmp.d + now.second});
        }
      }
    }
  }
}
int main() {
  cin >> n >> m >> a >> b;
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    if (c == a) G[u].push_back(v), G[v].push_back(u);
    V[u].push_back(make_pair(v, c));
    V[v].push_back(make_pair(u, c));
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt++;
      dfs(i, 0);
    }
  }
  sort(same + 1, same + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) {
    for (auto t : same[i]) {
      belong[t] = i;
    }
  }
  Dijkstra(1);
  for (int i = 1; i <= n; i++) {
    int ans = INF;
    for (int j = 0; j < (1 << 17); j++) {
      ans = min(ans, dis[j][i]);
    }
    cout << ans << " ";
  }
  return 0;
}
