#include <cstdio>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;
struct node {
int d, u, hp;
node(int d = 0, int u = 0, int hp = 0) : d(d), u(u), hp(hp) {}
};
bool operator < (node a, node b) {
return a.d > b.d;
}
vector<pair<int, int> > G[30010];
unordered_map<int, int> dis[30010];
queue<node> pq;
int n, m, k, x, y, z, a[30010];
void dijkstra() {
pq.emplace(0, 1, k);
dis[1][k] = 0;
while (!pq.empty()) {
node t = pq.front();
pq.pop();
// printf("%d %d %d\n", t.u, t.d, t.hp);
int nowdis = dis[t.u][t.hp];
t.hp = min(k, t.hp + a[t.u]);
for (auto [v, w] : G[t.u]) {
if (t.hp >= w) {
if (!dis[v].count(t.hp - w)) {
dis[v][t.hp - w] = nowdis + 1;
pq.emplace(nowdis + 1, v, t.hp - w);
}
}
}
}
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &x, &y, &z);
G[x].push_back({y, z});
G[y].push_back({x, z});
}
dijkstra();
int ans = 1e9;
for (auto d : dis[n]) {
ans = min(ans, d.second);
}
if (ans == 1e9) ans = -1;
printf("%d\n", ans);
return 0;
}