import core.stdc.stdio;
import std.typecons;
import std.conv;
import std.container;
import std.algorithm;

void main(){
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	int[] hs = new int[n];
	for(int i=0;i<n;i++)
		scanf("%d",&hs[i]);
	alias Tuple!(long,"cost",int,"idx") ci;
	ci[][] graph = new ci[][n];
	for(int i=0;i<m;i++){
		int a,b;
		long t;
		scanf("%d%d%lld",&a,&b,&t);
		--a;
		--b;
		if(hs[a]>=t)
			graph[a] ~= ci(t,b);
		if(hs[b]>=t)
			graph[b] ~= ci(t,a);
	}

	alias Tuple!(long,"cost",long,"down",int,"idx") cdi;
	alias BinaryHeap!(cdi[],"a>b") pq;
	pq q = pq(new cdi[400000],0);
	q.insert(cdi(max(0,hs[n-1]-x),0,0));
	long ans=-1;
	bool[] visited = new bool[n];
	
	while(!q.empty){
		cdi t = q.front;
		q.removeFront;
		with(t){
			if(idx==n-1){
				ans=cost;
				break;
			}
			if(visited[idx])
				continue;
			visited[idx] = true;
			foreach(cs;graph[idx]){
				if(!visited[cs.idx]){
					cdi nx;
					nx.idx = cs.idx;
					nx.down = down+cs.cost;
					if(x-nx.down>hs[cs.idx])
						nx.down = x-hs[cs.idx];
					if(x-nx.down<hs[n-1])
						nx.cost = hs[n-1]-(x-nx.down);
					nx.cost += nx.down;
					q.insert(nx);
				}
			}
		}
	}
	printf("%lld\n",ans);
}