#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, a, b, cnt, Newid, Size[N], id[N], nid[N], ans[N];
struct edge {
  int x, y, z;
  bool operator<(const edge &rhs) const { return z < rhs.z; }
} e[N << 2];
int tot = 0, head[N], to[N << 2], nxt[N << 2], len[N << 2];
void add_edge(int x, int y, int z) {
  nxt[++tot] = head[x];
  to[tot] = y;
  len[tot] = z;
  head[x] = tot;
}
int fa[N];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void Krusual() {
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = getfa(e[i].x), y = getfa(e[i].y);
    if (e[i].z == b || x == y) continue;
    fa[y] = fa[x];
  }
}
priority_queue<pair<int, pair<int, int>>> q;
int dis[1 << 18][80];
bool vis[1 << 18][80];
void Dijkstra() {
  memset(dis, 0x3f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  q.push(make_pair(0, make_pair(0, 1)));
  dis[0][1] = 0;
  while (!q.empty()) {
    int now = -q.top().first;
    pair<int, int> u = q.top().second;
    q.pop();
    ans[u.second] = min(ans[u.second], now);
    if (vis[u.first][u.second]) continue;
    vis[u.first][u.second] = 1;
    for (int i = head[u.second]; i; i = nxt[i]) {
      int v = to[i];
      if (id[v] == id[u.second] && len[i] == b) continue;
      if (nid[v] && (u.first & (1 << nid[v]))) continue;
      int S = u.first;
      if (nid[u.second] && nid[v] != nid[u.second]) S |= (1 << nid[u.second]);
      if (dis[u.first][u.second] + len[i] < dis[S][v]) {
        dis[S][v] = dis[u.first][u.second] + len[i];
        q.push(make_pair(-dis[S][v], make_pair(S, v)));
      }
    }
  }
}
int main() {
  cin >> n >> m >> a >> b;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    add_edge(e[i].x, e[i].y, e[i].z);
    add_edge(e[i].y, e[i].x, e[i].z);
  }
  sort(e + 1, e + m + 1);
  Krusual();
  for (int i = 1; i <= n; i++) {
    Size[getfa(i)]++;
    if (fa[i] == i) id[i] = ++cnt;
  }
  for (int i = 1; i <= n; i++) id[i] = id[getfa(i)];
  for (int i = 1; i <= n; i++)
    if (Size[i] >= 4) nid[i] = ++Newid;
  for (int i = 1; i <= n; i++) nid[i] = nid[getfa(i)];
  memset(ans, 0x3f, sizeof(ans));
  Dijkstra();
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
