#include <bits/stdc++.h>
using namespace std;
const int M = 18;
const int N = 75;
int d[1 << M][N], col[N], ans[N], sz, cnt, tmp;
bool vis[1 << M][N], vis1[N], vis2[N];
struct node {
  int val, st, x;
};
queue<node> q1, q2;
vector<int> tol[N], toh[N];
int n, m, a, b;
void dfs1(int x) {
  if (vis1[x]) return;
  sz++;
  vis1[x] = 1;
  for (int i = 0; i < tol[x].size(); i++) dfs1(tol[x][i]);
}
void dfs2(int x) {
  if (vis2[x]) return;
  col[x] = cnt, vis2[x] = 1;
  for (int i = 0; i < tol[x].size(); i++) dfs2(tol[x][i]);
}
int main() {
  memset(ans, 0x7f, sizeof(ans));
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (z == a)
      tol[x].push_back(y), tol[y].push_back(x);
    else
      toh[x].push_back(y), toh[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    sz = 0;
    if (!vis1[i]) dfs1(i);
    if (sz >= 4) dfs2(i), cnt++;
  }
  memset(vis1, 0, sizeof(vis1));
  tmp = cnt - 1;
  for (int i = 1; i <= n; i++) {
    sz = 0;
    if (!vis1[i]) dfs1(i);
    if (sz < 4) dfs2(i), cnt++;
  }
  memset(d, 0x3f, sizeof(d));
  d[col[1] <= tmp ? 1 << col[1] : 0][1] = 0;
  q1.push((node){0, col[1] <= tmp ? 1 << col[1] : 0, 1});
  while (q1.size() || q2.size()) {
    node s;
    if (!q1.size())
      s = q2.front(), q2.pop();
    else if (!q2.size())
      s = q1.front(), q1.pop();
    else if (q1.front().val < q2.front().val)
      s = q1.front(), q1.pop();
    else
      s = q2.front(), q2.pop();
    int x = s.x, st = s.st;
    if (vis[st][x]) continue;
    vis[st][x] = 1;
    ans[x] = min(ans[x], d[st][x]);
    for (int i = 0; i < tol[x].size(); i++) {
      int y = tol[x][i];
      if (d[st][y] > d[st][x] + a) {
        d[st][y] = d[st][x] + a;
        q1.push(node{d[st][y], st, y});
      }
    }
    for (int i = 0; i < toh[x].size(); i++) {
      int y = toh[x][i];
      if (col[x] == col[y]) continue;
      if (col[y] <= tmp && (st & (1 << col[y]))) continue;
      int st1 = st;
      if (col[y] <= tmp) st1 = st1 | (1 << col[y]);
      if (d[st1][y] > d[st][x] + b) {
        d[st1][y] = d[st][x] + b;
        q2.push(node{d[st1][y], st1, y});
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
