#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M], cc[M];
vector<int> adj[N];
ll dist[N];
int par[N];
int ee[N][N];

bool dij() {
	MMS(dist, 0x3f);
	MMS(par, -1);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			if (d > L)
				return 0;
			bool f = 1;
			while (cur != -1) {
				int nxt = par[cur];
				if (cc[ee[cur][nxt]] == 0) {
					cc[ee[cur][nxt]] = 1;
					if (f) {
						cc[ee[cur][nxt]] += L - d;
						f = 0;
					}
				}
				cur = nxt;
			}
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dij()) {
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M];
ll cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int ee[N][N];

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

bool dijEN() {
	MMS(distToEN, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		if (cur == st) {
			return d <= L;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

bool dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (cc[e] == 0) {
				cc[e] = max(1LL, L - d - distToEN[to]);
			}
			ll dd = d + cc[e];
			if (dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dijEN()) {
		dijST();
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M];
ll cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int ee[N][N];

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

bool dijEN() {
	MMS(distToEN, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		if (cur == st) {
			return d <= L;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

bool dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (dist[to] > OO) {
				if (cc[e] == 0) {
					cc[e] = max(1LL, L - d - distToEN[to]);
				}
				ll dd = d + cc[e];
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dijEN()) {
		dijST();
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M], cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int par[N];
int ee[N][N];
vector<int> zerIdx;

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

bool dijEN() {
	MMS(distToEN, 0x3f);
	MMS(par, -1);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		if (cur == st) {
			return d <= L;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				par[to] = cur;
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

bool dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (!cc[e])
				cc[e] = max(1LL, L - d - distToEN[to]);
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		if (cc[i] == 0)
			zerIdx.pb(i);
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dijEN()) {
		dijST();
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M], cc[M];
vector<int> adj[N];
ll dist[N];
int par[N];
int ee[N][N];

bool dij() {
	MMS(dist, 0x3f);
	MMS(par, -1);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			if (d > L)
				return 0;
			bool f = 1;
			while (cur != -1) {
				int nxt = par[cur];
				if (cc[ee[cur][nxt]] == 0) {
					cc[ee[cur][nxt]] = 1;
					if (f) {
						cc[ee[cur][nxt]] += L - d;
						f = 0;
					}
				}
				cur = nxt;
			}
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				par[to] = cur;
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dij()) {
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M];
ll cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int ee[N][N];

void dijEN() {
	MMS(distToEN, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
}

void dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (cc[e] == 0) {
				cc[e] = max(1LL, L - d - distToEN[to]);
			}
			ll dd = d + cc[e];
			if (dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	dijEN();
	dijST();
	if (distToEN[st] > L || dist[en] != L) {
		cout << "NO\n";
	} else {
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M];
ll cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int ee[N][N];

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

bool dijEN() {
	MMS(distToEN, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		if (cur == st) {
			return d <= L;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

bool dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return 1;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (cc[e] == 0) {
				if (d + distToEN[to] >= L)
					continue;
				cc[e] = max(1LL, L - d - distToEN[to]);
			}
			ll dd = d + cc[e];
			if (dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dijEN()) {
		dijST();
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcount(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 1003;
const int M = 10004;

int n, m, L, st, en;
int ff[M], tt[M];
ll cc[M];
vector<int> adj[N];
ll dist[N], distToEN[N];
int ee[N][N];

ll dij0() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		if (cur == en) {
			return d;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] && dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return -1;
}

bool dijEN() {
	MMS(distToEN, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, en));
	distToEN[en] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != distToEN[cur])
			continue;
		if (cur == st) {
			return d <= L;
		}
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			ll dd = d + cc[e];
			if (cc[e] == 0) {
				dd += 1;
			}
			if (distToEN[to] > dd) {
				distToEN[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
	return 0;
}

void dijST() {
	MMS(dist, 0x3f);
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > Q;
	Q.push(mp(0, st));
	dist[st] = 0;
	while (SZ(Q)) {
		int cur = Q.top().second;
		ll d = Q.top().first;
		Q.pop();
		if (d != dist[cur])
			continue;
		for (int i = 0; i < SZ(adj[cur]); i++) {
			int e = adj[cur][i];
			int to = (ff[e] == cur) ? tt[e] : ff[e];
			if (cc[e] == 0) {
				cc[e] = max(1LL, L - d - distToEN[to]);
			}
			ll dd = d + cc[e];
			if (dist[to] > dd) {
				dist[to] = dd;
				Q.push(mp(dd, to));
			}
		}
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> L >> st >> en;
	for (int i = 0; i < m; i++) {
		cin >> ff[i] >> tt[i] >> cc[i];
		adj[ff[i]].pb(i);
		adj[tt[i]].pb(i);
		ee[ff[i]][tt[i]] = ee[tt[i]][ff[i]] = i;
	}
	ll res = dij0();
	if (res != -1 && res <= L) {
		if (res < L) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < m; i++)
				cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
		}
		return 0;
	} else if (dijEN()) {
		dijST();
		cout << "YES\n";
		for (int i = 0; i < m; i++)
			cout << ff[i] << " " << tt[i] << " " << (cc[i] ? cc[i] : OO) << "\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 20000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b;
  next[cnt] = adj[a];
  cost[cnt] = c;
  adj[a] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(mid, 1) <= len) l = mid; else r = mid - 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 20000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b;
  next[cnt] = adj[a];
  cost[cnt] = c;
  adj[a] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, e[p].w ? e[p].w : v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (dijkstra(mid, 1) <= len) r = mid; else l = mid + 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  if (!e[p].w) e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 40000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b, next[cnt] = adj[a], cost[cnt] = c, adj[a] = cnt++;
  to[cnt] = a, next[cnt] = adj[b], cost[cnt] = 0, adj[b] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, e[p].w ? e[p].w : v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (dijkstra(mid, 1) <= len) r = mid; else l = mid + 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  if (!e[p].w) e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 20000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b;
  next[cnt] = adj[a];
  cost[cnt] = c;
  adj[a] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(mid, 1) <= len) l = mid; else r = mid - 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 40000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b, next[cnt] = adj[a], cost[cnt] = c, adj[a] = cnt++;
  to[cnt] = a, next[cnt] = adj[b], cost[cnt] = c, adj[b] = cnt++;
}

struct {
  int u, v, w;
} e[E];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, e[p].w ? e[p].w : v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (dijkstra(mid, 1) <= len) r = mid; else l = mid + 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  if (!e[p].w) e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 40000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b, next[cnt] = adj[a], cost[cnt] = c, adj[a] = cnt++;
  to[cnt] = a, next[cnt] = adj[b], cost[cnt] = c, adj[b] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, e[p].w ? e[p].w : v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (dijkstra(mid, 1) <= len) r = mid; else l = mid + 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  if (!e[p].w) e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long i64;

const int N = 1000 + 10, E = 20000 + 10, INF = 0x3f3f3f3f;

int n, m, len, s, t;

int adj[N], to[E], next[E], cost[E], cnt;

void link(int a, int b, int c) {
  to[cnt] = b;
  next[cnt] = adj[a];
  cost[cnt] = c;
  adj[a] = cnt++;
}

struct {
  int u, v, w;
} e[N];

i64 dist[N];

i64 dijkstra(int p, int v) {
  memset(adj, 0, n * sizeof(int));
  cnt = 2;
  for (int i = 0; i < p; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : 1);
  link(e[p].u, e[p].v, e[p].w ? e[p].w : v);
  for (int i = p + 1; i < m; ++i) link(e[i].u, e[i].v, e[i].w ? e[i].w : INF);
  static std::pair<i64, int> heap[N * N];
  int top = 1;
  memset(dist, 0x3f, n * sizeof(i64));
  for (heap[0] = std::make_pair(dist[s] = 0, s); top;) {
    std::pop_heap(heap, heap + top);
    std::pair<i64, int> cur = heap[--top];
    int a = cur.second;
    if (-cur.first > dist[a]) continue;
    for (int i = adj[a]; i; i = next[i]) {
      int b = to[i], c = cost[i];
      if (dist[a] + c < dist[b]) {
        heap[top++] = std::make_pair(-(dist[b] = dist[a] + c), b);
        std::push_heap(heap, heap + top);
      }
    }
  }
  return dist[t];
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &len, &s, &t);
  for (int i = 0; i < m; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  if (dijkstra(0, INF) < len || dijkstra(m - 1, 1) > len) return puts("NO"), 0;
  puts("YES");
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(mid, 1) <= len) l = mid; else r = mid - 1;
  }
  int p = l;
  l = 1, r = len;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (dijkstra(p, mid) <= len) l = mid; else r = mid - 1;
  }
  for (int i = 0; i < p; ++i) if (!e[i].w) e[i].w = 1;
  e[p].w = l;
  for (int i = p + 1; i < m; ++i) if (!e[i].w) e[i].w = INF;
  for (int i = 0; i < m; ++i) printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
int p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,int>> e[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && y.second<d1[y.first]+diff-d2[x]){
				y.second=d1[y.first]+diff-d2[x];
				p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
			}
			if (d2[y.first]>v+y.second){
				d2[y.first]=v+y.second;
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d1[t]!=L) return puts("NO"),0;
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
ll p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,ll>> e[N];
priority_queue<pair<int,ll>,vector<pair<int,ll>>,greater<pair<int,ll>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+p2[x][y.first]){
				d1[y.first]=v+p2[x][y.first];
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && p2[x][y.first]<d1[y.first]+diff-d2[x]){
				p2[y.first][x]=p2[x][y.first]=d1[y.first]+diff-d2[x];
			}
			if (d2[y.first]>v+p2[x][y.first]){
				d2[y.first]=v+p2[x][y.first];
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1,p2[x][y]=p2[y][x]=1;
		else p2[x][y]=p2[y][x]=v;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
ll p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<int> e[N];
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({0,root});
	while (!q.empty()){
		int x=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (int y:e[x]){
			if (d1[y]>d1[x]+p2[x][y]){
				d1[y]=d1[x]+p2[x][y];
				q.push({d1[y],y});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({0,root});
	while (!q.empty()){
		int x=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y] && p2[x][y]<d1[y]+diff-d2[x]){
				p2[y][x]=p2[x][y]=d1[y]+diff-d2[x];
			}
			if (d2[y]>d2[x]+p2[x][y]){
				d2[y]=d2[x]+p2[x][y];
				q.push({d2[y],y});
			}
		}
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1,p2[x][y]=p2[y][x]=1;
		else p2[x][y]=p2[y][x]=v;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%lld %lld %lld\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
ll p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,ll>> e[N];
priority_queue<pair<int,ll>,vector<pair<int,ll>>,greater<pair<int,ll>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && p2[x][y.first]<d1[y.first]+diff-d2[x]){
				p2[y.first][x]=p2[x][y.first]=d1[y.first]+diff-d2[x];
			}
			if (d2[y.first]>v+p2[x][y.first]){
				d2[y.first]=v+p2[x][y.first];
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1,p2[x][y]=p2[y][x]=1;
		else p2[x][y]=p2[y][x]=v;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
int p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,int>> e[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && y.second<d1[y.first]+diff-d2[x]){
				y.second=d1[y.first]+diff-d2[x];
				p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
			}
			if (d2[y.first]>v+y.second){
				d2[y.first]=v+y.second;
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
int p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,int>> e[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && y.second<d1[y.first]+diff-d2[x]){
				y.second=d1[y.first]+diff-d2[x];
				p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
			}
			if (d2[y.first]>v+y.second){
				d2[y.first]=v+y.second;
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
int p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,int>> e[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		int v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && p2[x][y.first]<d1[y.first]+diff-d2[x]){
				p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
			}
			if (d2[y.first]>v+p2[x][y.first]){
				d2[y.first]=v+p2[x][y.first];
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1,p2[x][y]=p2[y][x]=1;
		else p2[x][y]=p2[y][x]=v;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005;
int n,m,k,s,t,f[N],x,y,v;
ll p1[N*10][2],p2[N][N],p[N][N];
ll d1[N],d2[N],L,diff;
vector<pair<int,ll>> e[N];
priority_queue<pair<int,ll>,vector<pair<int,ll>>,greater<pair<int,ll>>> q;
void dijkstr(int root){
	memset(f,0,sizeof(f));
	memset(d1,0x3f,sizeof(d1));
	d1[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (d1[y.first]>v+(y.second==0?1:y.second)){
				d1[y.first]=v+(y.second==0?1:y.second);
				q.push({y.first,d1[y.first]});
			}
		}
	}
}
void dijkstr1(int root){
	memset(f,0,sizeof(f));
	memset(d2,0x3f,sizeof(d2));
	d2[root]=0;
	q.push({root,0});
	while (!q.empty()){
		int x=q.top().first;
		ll v=q.top().second;
		q.pop();
		if (f[x]) continue;
		f[x]=1;
		for (auto y:e[x]){
			if (p[x][y.first] && p2[x][y.first]<d1[y.first]+diff-d2[x]){
				p2[y.first][x]=p2[x][y.first]=d1[y.first]+diff-d2[x];
			}
			if (d2[y.first]>v+p2[x][y.first]){
				d2[y.first]=v+p2[x][y.first];
				q.push({y.first,d2[y.first]});
			}
		}
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L>>s>>t;
	for (int i=1;i<=m;++i){
		cin>>x>>y>>v;
		p1[i][0]=x;
		p1[i][1]=y;
		if (!v) p[x][y]=p[y][x]=1,p2[x][y]=p2[y][x]=1;
		else p2[x][y]=p2[y][x]=v;
		e[x].push_back({y,v});
		e[y].push_back({x,v});
	}
	dijkstr(s);
	if (d1[t]>L) return puts("NO"),0;
	diff=L-d1[t];
	dijkstr1(s);
	if (d2[t]!=L) return puts("NO"),0;
	for (int x=0;x<n;++x)
		for (auto y:e[x]){
			p2[y.first][x]=p2[x][y.first]=max(p2[x][y.first],y.second);
		}
	puts("YES");
	for (int i=1;i<=m;++i)
		printf("%d %d %d\n",p1[i][0],p1[i][1],p2[p1[i][0]][p1[i][1]]);

}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	LL rem = L - l;
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to] - d[fr] - 1);
			rem -= del;
			v[fr][to] = v[to][fr] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	LL rem = L - l;
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to]);
			rem -= del;
			v[fr][to] = v[to][fr] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	LL rem = L - l;
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to] - d[fr]);
			rem -= del;
			v[fr][to] = v[to][fr] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	LL rem = L - d[t];
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to]);
			rem -= del;
			v[fr][to] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN], md[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		if(~pre[tp] && v[tp][pre[tp]] == 0){
			v[tp][pre[tp]] = v[pre[tp]][tp] = 1;
			md[tp][pre[tp]] = md[pre[tp]][tp] = 1;
		}
		tp = pre[tp];
	}
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(md[fr][to]){
			dk(0);
			v[fr][to] = v[to][fr] += L - d[t];
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
bool vis[MXN];
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	memset(vis, 0, sizeof(vis));
	d[s] = 0;
	pq.push(MP(0, s));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(-1);
			v[fr][to] = v[to][fr] = L - d[t] + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	d[s] = 0;
	pq.push(MP(s, 0));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(d[t] != INF) continue;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	printf("%lld %lld\n", l, h);
	LL rem = L - d[t];
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to]);
			rem -= del;
			v[fr][to] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-9
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define MXN 5005
#define INF (LL)1e18

int n, m, L, s, t, fr, to, w, pre[MXN];
LL d[MXN], h, l;
map<int, LL> v[MXN];
stack<int> st;
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;

void dk(int bk){
	for(int i = 0; i < n; i ++) d[i] = INF;
	d[s] = 0;
	pq.push(MP(s, 0));
	while(!pq.empty()){
		LL x = pq.top().S; pq.pop();
		if(d[t] != INF) continue;
		for(auto i : v[x]){
			if(i.S == bk) continue;
			LL val = (i.S == 0 ? 1 : i.S);
			if(d[x] + val < d[i.F]){
				pq.push(MP(d[i.F] = d[x] + val, i.F));
				pre[i.F] = x;
			}
		}
	}
}
int main(){
	scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
	memset(pre, -1, sizeof(pre));
	while(m --){
		scanf("%d%d%d", &fr, &to, &w);
		v[fr][to] = v[to][fr] = w;
	}
	dk(0); h = d[t];
	dk(-1); l = d[t];
	if(h < L || l > L){
		puts("NO");
		return 0;
	}
	int tp = t;
	while(~tp){
		st.push(tp);
		tp = pre[tp];
	}
	LL rem = L - d[t];
	while(SZ(st) > 1){
		fr = st.top(); st.pop(); to = st.top();
		if(!v[fr][to]){
			dk(0);
			LL del = min(rem, d[to]);
			rem -= del;
			v[fr][to] = del + 1;
		}
	}
	puts("YES");
	for(int i = 0; i < n; i ++) for(auto j : v[i]) if(i < j.F) printf("%d %d %lld\n", i, j.F, (j.S == 0 ? (LL)1e18 : j.S));
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    int cnt = 0;
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            cnt++;
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(i.ff) != s.end())
                    s.erase(i.ff);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    fastread;
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    int m[1001][1001];
    f(i, 0, 1001) f(j, 0, 1001) m[i][j] = inf;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[s][d] = w; m[d][s] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[s][t] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[v[i]][v[i+1]] != 0)
        {
            sum += m[v[i]][v[i+1]]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[v[j]][v[j+1]] == 0) t++;
            else t += m[v[j]][v[j+1]];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[v[i]][v[i+1]] = m[v[i+1]][v[i]] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[i][g[i][j].ff] = ((m[i][g[i][j].ff] <= 0)? 1e15 : m[i][g[i][j].ff]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    f(i, 0, n)
    {
        f(j, 0, n)
        {
            if(ss.find({i, j}) == ss.end()) continue;
            cout<<i<<" "<<j<<" "<<m[i][j]<<"\n";
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    int cnt = 0;
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            cnt++;
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(t) != s.end())
                    s.erase(t);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
            if(cnt > 5e4) return ;
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    fastread;
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    int m[1001][1001];
    f(i, 0, 1001) f(j, 0, 1001) m[i][j] = inf;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[s][d] = w; m[d][s] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[s][t] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[v[i]][v[i+1]] != 0)
        {
            sum += m[v[i]][v[i+1]]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[v[j]][v[j+1]] == 0) t++;
            else t += m[v[j]][v[j+1]];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[v[i]][v[i+1]] = m[v[i+1]][v[i]] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[i][g[i][j].ff] = ((m[i][g[i][j].ff] <= 0)? 1e15 : m[i][g[i][j].ff]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    f(i, 0, n)
    {
        f(j, 0, n)
        {
            if(ss.find({i, j}) == ss.end()) continue;
            cout<<i<<" "<<j<<" "<<m[i][j]<<"\n";
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    int cnt = 0;
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            cnt++;
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(i.ff) != s.end())
                    s.erase(i.ff);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    fastread;
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    int m[1001][1001];
    f(i, 0, 1001) f(j, 0, 1001) m[i][j] = inf;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[s][d] = w; m[d][s] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     x = 0; bfs(0, S);
     x = 1; bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    x = 2; bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[s][t] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[v[i]][v[i+1]] != 0)
        {
            sum += m[v[i]][v[i+1]]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[v[j]][v[j+1]] == 0) t++;
            else t += m[v[j]][v[j+1]];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[v[i]][v[i+1]] = m[v[i+1]][v[i]] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[i][g[i][j].ff] = ((m[i][g[i][j].ff] <= 0)? 1e15 : m[i][g[i][j].ff]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    x = 0; bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    f(i, 0, n)
    {
        f(j, 0, n)
        {
            if(ss.find({i, j}) == ss.end()) continue;
            cout<<i<<" "<<j<<" "<<m[i][j]<<"\n";
        }
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(t) != s.end())
                    s.erase(t);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    map<key, int> m;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[{s, d}] = w; m[{d, s}] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);a

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[{s, t}] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[{v[i], v[i+1]}] != 0)
        {
            sum += m[{v[i], v[i+1]}]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[{v[j], v[j+1]}] == 0) t++;
            else t += m[{v[j], v[j+1]}];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[{v[i], v[i+1]}] = m[{v[i+1], v[i]}] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[{i, g[i][j].ff}] = ((m[{i, g[i][j].ff}] <= 0)? 1e15 : m[{i, g[i][j].ff}]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    for(pair<key, int> k : m)
    {
        if(ss.find(k.ff) == ss.end()) continue;
        cout<<k.ff.ff<<" "<<k.ff.ss<<" "<<k.ss<<"\n";
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e8;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(t) != s.end())
                    s.erase(t);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    map<key, int> m;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[{s, d}] = w; m[{d, s}] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    while(s != T)
    {
        int t = pre[s];
        if(m[{s, t}] == 0) cnt++;
        s = t;
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
    while(s != T)
    {
        int t = pre[s];
        if(t == -1 || m[{s, t}] != 0)
        {
            sum += m[{s, t}];
            s = t; continue;
        }
        int y = min(L-cnt+1, dist[0][t] - sum);
        L -= y; cnt--;
//        cout<<s<<" "<<t<<" "<<y<<" "<<L<<" "<<dist[0][t]<<" "<<dist[1][s]<<"\n";
        sum += y;
        m[{s, t}] = m[{t, s}] = y;
        s = t;
    }
    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[{i, g[i][j].ff}] = ((m[{i, g[i][j].ff}] == 0)? 1e15 : m[{i, g[i][j].ff}]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    for(pair<key, int> k : m)
    {
        if(ss.find(k.ff) == ss.end()) continue;
        cout<<k.ff.ff<<" "<<k.ff.ss<<" "<<k.ss<<"\n";
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(t) != s.end())
                    s.erase(t);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    map<key, int> m;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[{s, d}] = w; m[{d, s}] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[{s, t}] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[{v[i], v[i+1]}] != 0)
        {
            sum += m[{v[i], v[i+1]}]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[{v[j], v[j+1]}] == 0) t++;
            else t += m[{v[j], v[j+1]}];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[{v[i], v[i+1]}] = m[{v[i+1], v[i]}] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[{i, g[i][j].ff}] = ((m[{i, g[i][j].ff}] <= 0)? 1e15 : m[{i, g[i][j].ff}]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    for(pair<key, int> k : m)
    {
        if(ss.find(k.ff) == ss.end()) continue;
        cout<<k.ff.ff<<" "<<k.ff.ss<<" "<<k.ss<<"\n";
    }
}


#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 2e18;
using namespace std;

int dist[3][1001], pre[1001];
vector<key> g[1001];
int x = 0, n;

class cmp{
    public:
        bool operator()(int a, int b)
        {
            return dist[x][a] < dist[x][b] || (dist[x][a] == dist[x][b] && a < b);
        }
};

void bfs(int x, int src)
{
    int cnt = 0;
    f(i, 0, 1001) dist[x][i] = inf;
    dist[x][src] = 0;
    pre[src] = -1;
    set<int, cmp> s; s.insert(src);
    while(!s.empty())
    {
        int t = *s.begin(); s.erase(s.begin());
        for(key i : g[t])
        {
            cnt++;
            if(dist[x][i.ff] > dist[x][t] + i.ss)
            {
                if(s.find(t) != s.end())
                    s.erase(t);
                dist[x][i.ff] = dist[x][t] + i.ss;
                s.insert(i.ff);
                pre[i.ff] = t;
            }
            if(cnt > 2e5) return ;
        }
    }
//    cout<<x<<"      "; f(i, 0, n) cout<<dist[x][i]<<" "; cout<<"\n";
}

main()
{
    fastread;
    int M, L, S,  T; cin>>n>>M>>L>>S>>T;
    int m[1001][1001];
    f(i, 0, 1001) f(j, 0, 1001) m[i][j] = inf;
    set<key> ss;

    f(i, 0, M)
    {
        int s, d, w; cin>>s>>d>>w;
        if(w == 0)
        {
            g[s].pb({d, inf}); g[d].pb({s, inf});
        }
        else
        {
            g[s].pb({d, w}); g[d].pb({s, w});
        }
        m[s][d] = w; m[d][s] = w;
        ss.insert({s, d});
    }
  //  f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
     bfs(0, S); bfs(1, T);

    f(i, 0, n)
        f(j, 0, g[i].size())
            if(g[i][j].ss == inf)
                g[i][j].ss = 1;
    bfs(2, T);

    if(dist[2][S] > L)
    {
        cout<<"NO"; return 0;
    }

//    f(i, 0, n) cout<<pre[i]<<" "; cout<<"\n";
    int cnt = 0, s = S;
    vector<int> v; v.pb(s);
    while(s != T)
    {
        int t = pre[s];
        if(m[s][t] == 0) cnt++;
        s = t;  v.pb(s);
    }
//    cout<<cnt<<"\n";
    s = S;
    int tl = L;
    L -= (dist[2][S] - cnt);
    int sum = 0;
 //   for(int i : v) cout<<i<<" "; cout<<"\n";
    f(i, 0, v.size()-1)
    {
        if(m[v[i]][v[i+1]] != 0)
        {
            sum += m[v[i]][v[i+1]]; continue;
        }
        int t = sum, y = dist[0][v[i+1]] - sum;
    //    cout<<y<<" ";
        f(j, i+1, v.size() - 1)
        {
            if(m[v[j]][v[j+1]] == 0) t++;
            else t += m[v[j]][v[j+1]];
            y = min(y, dist[0][v[j+1]] - t);
    //        cout<<i<<" "<<j<<" "<<t<<" "<<y<<"\n";
        }
        //cout<<y<<" ";
        y = min(y, L-cnt+1); L -= y; cnt--;
        m[v[i]][v[i+1]] = m[v[i+1]][v[i]] = y;
        sum += y;
    //    cout<<v[i]<<" "<<v[i+1]<<" "<<L<<" "<<y<<" "<<cnt<<" "<<sum<<"\n\n";
    }

    f(i, 0, n)
        f(j, 0, g[i].size())
            g[i][j].ss = m[i][g[i][j].ff] = ((m[i][g[i][j].ff] <= 0)? 1e15 : m[i][g[i][j].ff]);
 //   f(i, 0, n){ f(j, 0, g[i].size()) cout<<g[i][j].ff<<" "<<g[i][j].ss<<"   "; cout<<"\n"; }
    bfs(0, S);

    if(dist[0][T] != tl)
    {
        cout<<"NO"; return 0;
    }

    cout<<"YES\n";
    f(i, 0, n)
    {
        f(j, 0, n)
        {
            if(ss.find({i, j}) == ss.end()) continue;
            cout<<i<<" "<<j<<" "<<m[i][j]<<"\n";
        }
    }
}