#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MAXM = 10005;
const int INF = 0x3f3f3f3f;
struct Edge {
  int u, v, w;
} e[MAXM];
vector<Edge> g[MAXN];
int n, m, L, s, t;
void input() {
  scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
  s++;
  t++;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    e[i].u++;
    e[i].v++;
  }
}
void addedge(int a, int b, int c) { g[a].push_back((Edge){a, b, c}); }
template <typename T>
bool relax(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
int dijkstra() {
  static int dis[MAXN];
  static bool vis[MAXN];
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (int i = 1; i <= n; i++) dis[i] = INF;
  for (int i = 1; i <= n; i++) vis[i] = 0;
  q.push(make_pair(dis[s] = 0, s));
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (auto ee : g[x]) {
      int y = ee.v;
      if (relax(dis[y], dis[x] + ee.w)) q.push(make_pair(dis[y], y));
    }
  }
  return dis[t];
}
bool check(int p) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= m; i++) {
    if (e[i].w) {
      addedge(e[i].u, e[i].v, e[i].w);
      addedge(e[i].v, e[i].u, e[i].w);
    } else {
      int w = ++cnt <= p ? 1 : L + 1;
      addedge(e[i].u, e[i].v, w);
      addedge(e[i].v, e[i].u, w);
    }
  }
  return dijkstra() <= L;
}
bool check2(int len, int p) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= m; i++) {
    if (e[i].w) {
      addedge(e[i].u, e[i].v, e[i].w);
      addedge(e[i].v, e[i].u, e[i].w);
    } else {
      int w;
      ++cnt;
      if (cnt < p)
        w = 1;
      else if (cnt == p)
        w = len;
      else
        w = L + 1;
      addedge(e[i].u, e[i].v, w);
      addedge(e[i].v, e[i].u, w);
    }
  }
  return dijkstra() <= L;
}
void solve() {
  int l = 1, r = 0;
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= m; i++) {
    if (e[i].w) {
      addedge(e[i].u, e[i].v, e[i].w);
      addedge(e[i].v, e[i].u, e[i].w);
    }
  }
  int mini = dijkstra();
  if (mini < L) {
    puts("NO");
    return;
  }
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= m; i++) {
    if (e[i].w) {
      addedge(e[i].u, e[i].v, e[i].w);
      addedge(e[i].v, e[i].u, e[i].w);
    } else {
      addedge(e[i].u, e[i].v, 1);
      addedge(e[i].v, e[i].u, 1);
      r++;
    }
  }
  mini = dijkstra();
  if (mini > L) {
    puts("NO");
    return;
  }
  int res, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      res = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  int len;
  l = 1, r = L;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check2(mid, res)) {
      len = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  int cnt = 0;
  puts("YES");
  for (int i = 1; i <= m; i++) {
    if (e[i].w == 0) {
      ++cnt;
      if (cnt < res) {
        e[i].w = 1;
      } else if (cnt == res) {
        e[i].w = len;
      } else {
        e[i].w = L + 1;
      }
    }
    printf("%d %d %d\n", e[i].u - 1, e[i].v - 1, e[i].w);
  }
}
int main() {
  input();
  solve();
  return 0;
}
