// Created on 2022/07/25.
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (b); i >= (a); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e5 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> iv red(T &x) { x -= mod, x += x >> 31 & mod;}
template <class T = ll> T read() {
T f = 1, a = 0;
char ch = getchar() ;
while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
while (isdigit(ch)) { a = (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
return a * f ;
}
ll n, m, s, t, L;
ll u[maxn], v[maxn], w[maxn];
struct Edge {ll to, flow, c, rev; };
vector<Edge> edge[maxn];
ll level[maxn], start[maxn];
qi q;
void add(ll u, ll v, ll c) {
Edge a{v, 0, c, edge[v].size()};
Edge b{u, 0, 0, edge[u].size()};
edge[u].pb(a);
edge[v].pb(b);
}
bool BFS() {
fill(level + 1, level + n + 1, -1);
level[s] = 0;
q.push(s);
while (!q.empty()) {
ll u = q.front();
q.pop();
for (auto e : edge[u]) if (level[e.to] < 0 && e.flow < e.c) {
level[e.to] = level[u] + 1;
q.push(e.to);
}
}
return level[t] < 0 ? false : true;
}
ll sendFlow(ll u, ll flow) {
if (u == t) return flow;
for (; start[u] < edge[u].size(); ++start[u]) {
Edge &e = edge[u][start[u]];
if (level[e.to] == level[u] + 1 && e.flow < e.c) {
ll cur_flow = min(flow, e.c - e.flow);
ll tmp_flow = sendFlow(e.to, cur_flow);
if (tmp_flow > 0) {
e.flow += tmp_flow;
edge[e.to][e.rev].flow -= tmp_flow;
return tmp_flow;
}
}
}
return 0;
}
ll DinicMaxFlow() {
if (s == t) return -1;
ll ret = 0;
while (BFS()) {
clr(start);
while (ll flow = sendFlow(s, INT_MAX)) {
ret += flow;
}
}
return ret;
}
signed main() {
n = read(), m = read();
rep(i, 1, m) u[i] = read(), v[i] = read(), w[i] = read();
s = read(), t = read(), L = read();
rep(i, 1, m) if (w[i] < L) add(u[i], v[i], 1), add(v[i], u[i], 1);
ll ans = DinicMaxFlow();
rep(i, 1, n) vector<Edge>().swap(edge[i]);
rep(i, 1, m) if (w[i] > L) add(u[i], v[i], 1), add(v[i], u[i], 1);
ans += DinicMaxFlow();
printf("%lld\n", ans);
return 0;
}