#include <bits/stdc++.h>
using namespace std;
vector<int> adj[77];
int root[77];
int dis[77][77];
int vst[77];
int find(int u) { return root[u] == u ? u : root[u] = find(root[u]); }
vector<int> vec[77];
int id[77];
int D[1 << 17][77];
int B(int first) {
  if (first < 0) return 0;
  return 1 << first;
}
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  for (int i = 1; i <= n; i++) root[i] = i;
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    if (w == a) {
      dis[u][v] = dis[v][u] = a;
      u = find(u);
      v = find(v);
      root[u] = v;
    } else {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  for (int i = 1; i <= n; i++) dis[i][i] = 0;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
  int nn = 0;
  for (int i = 1; i <= n; i++) vec[find(i)].push_back(i);
  for (int i = 1; i <= n; i++) {
    if (vec[i].size() > 3)
      id[i] = nn++;
    else
      id[i] = -1;
  }
  for (int i = 1; i <= n; i++) id[i] = id[find(i)];
  memset(D, 0x3f, sizeof(D));
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      q;
  D[B(id[1])][1] = 0;
  q.push(pair<int, pair<int, int> >(0, pair<int, int>(B(id[1]), 1)));
  while (!q.empty()) {
    pair<int, pair<int, int> > p = q.top();
    q.pop();
    if (D[p.second.first][p.second.second] < p.first) continue;
    int u = p.second.second;
    for (int v : vec[root[u]]) {
      if (D[p.second.first][v] > p.first + dis[u][v]) {
        D[p.second.first][v] = p.first + dis[u][v];
        q.push(pair<int, pair<int, int> >(D[p.second.first][v],
                                          pair<int, int>(p.second.first, v)));
      }
    }
    for (int v : adj[u]) {
      if (p.second.first & B(id[v])) continue;
      if (root[u] == root[v]) continue;
      if (D[p.second.first | B(id[v])][v] > p.first + b) {
        D[p.second.first | B(id[v])][v] = p.first + b;
        q.push(pair<int, pair<int, int> >(
            p.first + b, pair<int, int>(p.second.first | B(id[v]), v)));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int mn = 1 << 30;
    for (int j = 0; j < 1 << nn; j++) mn = min(mn, D[j][i]);
    printf("%d ", mn);
  }
  return 0;
}
