// ~~ icebear love attttt ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "robot"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, m, s, k;
vector<ii> G[N];
int score[N];
bool vis[N], vis2[N];
ll cur_sum;
int test(int u) {
priority_queue<ii, vector<ii>, greater<ii>> Q;
vector<int> nodes;
Q.push(mp(0, u));
int ans = 0;
while(!Q.empty()) {
int w, u; tie(w, u) = Q.top(); Q.pop();
if (w > cur_sum) break;
if (vis2[u]) continue;
vis2[u] = true;
nodes.pb(u);
for(ii x : G[u]) if (!vis[x.fi] && !vis2[x.fi]) {
Q.push(mp(x.se, x.fi));
}
}
for(int u : nodes) vis2[u] = false;
return (int)nodes.size();
}
void init(void) {
cin >> n >> m >> s >> k;
FOR(i, 1, n) cin >> score[i];
FOR(i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
G[u].pb(mp(v, w));
G[v].pb(mp(u, w));
}
}
void process(void) {
priority_queue<ii, vector<ii>, greater<ii>> Q;
Q.push(mp(0, s));
while(!Q.empty()) {
int u, w; tie(w, u) = Q.top();
Q.pop();
if (vis[u]) continue;
if (w > cur_sum) break;
cur_sum += score[u];
vis[u] = true;
for(ii x : G[u]) if (!vis[x.fi]) {
Q.push(mp(x.se, x.fi));
}
}
int ans = count(vis, vis + n + 1, true), add = 0;
if (k == 1) {
while(!Q.empty()) {
int u = Q.top().se; Q.pop();
maximize(add, test(u));
}
}
cout << ans + add;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Ly8gfn4gaWNlYmVhciBsb3ZlIGF0dHR0dCB+fgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IGlpOwp0eXBlZGVmIHBhaXI8aW50LCBpaT4gaWlpOwoKdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGJvb2wgbWluaW1pemUoVCAmYSwgY29uc3QgVCAmYikgewogICAgICAgIGlmIChhID4gYikgcmV0dXJuIGEgPSBiLCB0cnVlOwogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCnRlbXBsYXRlPGNsYXNzIFQ+CiAgICBib29sIG1heGltaXplKFQgJmEsIGNvbnN0IFQgJmIpIHsKICAgICAgICBpZiAoYSA8IGIpIHJldHVybiBhID0gYiwgdHJ1ZTsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CgojZGVmaW5lIEZPUihpLGEsYikgZm9yKGludCBpPShhKTsgaTw9KGIpOyArK2kpCiNkZWZpbmUgRk9SUihpLGEsYikgZm9yKGludCBpPShhKTsgaT49KGIpOyAtLWkpCiNkZWZpbmUgUkVQKGksIG4pIGZvcihpbnQgaT0wOyBpPChuKTsgKytpKQojZGVmaW5lIFJFRChpLCBuKSBmb3IoaW50IGk9KG4pLTE7IGk+PTA7IC0taSkKI2RlZmluZSBNQVNLKGkpICgxTEwgPDwgKGkpKQojZGVmaW5lIEJJVChTLCBpKSAoKChTKSA+PiAoaSkpICYgMSkKI2RlZ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KICAgIGNpbiA+PiBuID4+IG0gPj4gcyA+PiBrOwogICAgRk9SKGksIDEsIG4pIGNpbiA+PiBzY29yZVtpXTsKICAgIEZPUihpLCAxLCBtKSB7CiAgICAgICAgaW50IHUsIHYsIHc7CiAgICAgICAgY2luID4+IHUgPj4gdiA+PiB3OwogICAgICAgIEdbdV0ucGIobXAodiwgdykpOwogICAgICAgIEdbdl0ucGIobXAodSwgdykpOwogICAgfQp9Cgp2b2lkIHByb2Nlc3Modm9pZCkgewogICAgcHJpb3JpdHlfcXVldWU8aWksIHZlY3RvcjxpaT4sIGdyZWF0ZXI8aWk+PiBROwogICAgUS5wdXNoKG1wKDAsIHMpKTsKICAgIHdoaWxlKCFRLmVtcHR5KCkpIHsKICAgICAgICBpbnQgdSwgdzsgdGllKHcsIHUpID0gUS50b3AoKTsKICAgICAgICBRLnBvcCgpOwogICAgICAgIGlmICh2aXNbdV0pIGNvbnRpbnVlOwogICAgICAgIGlmICh3ID4gY3VyX3N1bSkgYnJlYWs7CiAgICAgICAgY3VyX3N1bSArPSBzY29yZVt1XTsKICAgICAgICB2aXNbdV0gPSB0cnVlOwogICAgICAgIGZvcihpaSB4IDogR1t1XSkgaWYgKCF2aXNbeC5maV0pIHsKICAgICAgICAgICAgUS5wdXNoKG1wKHguc2UsIHguZmkpKTsKICAgICAgICB9CiAgICB9CiAgICBpbnQgYW5zID0gY291bnQodmlzLCB2aXMgKyBuICsgMSwgdHJ1ZSksIGFkZCA9IDA7CiAgICBpZiAoayA9PSAxKSB7CiAgICAgICAgd2hpbGUoIVEuZW1wdHkoKSkgewogICAgICAgICAgICBpbnQgdSA9IFEudG9wKCkuc2U7IFEucG9wKCk7CiAgICAgICAgICAgIG1heGltaXplKGFkZCwgdGVzdCh1KSk7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBhbnMgKyBhZGQ7Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgaWYgKGZvcGVuKHRhc2siLmlucCIsICJyIikpIHsKICAgICAgICBmcmVvcGVuKHRhc2siLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4odGFzayIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW50IHRjID0gMTsKLy8gIGNpbiA+PiB0YzsKICAgIHdoaWxlKHRjLS0pIHsKICAgICAgICBpbml0KCk7CiAgICAgICAgcHJvY2VzcygpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K