Problem: Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful.

One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1 through N inclusive) and M bidirectional transportation pipelines connecting the domes. In dome i, Pi citizens reside currently and there is a nuclear shelter capable of protecting Ki citizens. Also, it takes Di days to travel from one end to the other end of pipeline i.

It has been turned out that this city will be polluted by nuclear radiation in L days after today. So each citizen should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach their shelters in exactly or more than L days.

How many citizens can survive at most in this situation?



Input

The input consists of multiple test cases. Each test case begins with a line consisting of three integers N, M and L (1 ≤ N ≤ 100, M ≥ 0, 1 ≤ L ≤ 10000). This is followed by M lines describing the configuration of transportation pipelines connecting the domes. The i-th line contains three integers Ai, Bi and Di (1 ≤ Ai < Bi ≤ N, 1 ≤ Di ≤ 10000), denoting that the i-th pipeline connects dome Ai and Bi. There is at most one pipeline between any pair of domes. Finally, there come two lines, each consisting of N integers. The first gives P1 , . . ., PN (0 ≤ Pi ≤ 106) and the second gives K1 , . . ., KN (0 ≤ Ki ≤ 106).

The input is terminated by EOF. All integers in each line are separated by a whitespace.

Output

For each test case, print in a line the maximum number of people who can survive.

Example

Input

1 0 1
51
50
2 1 1
1 2 1
1000 0
0 1000
4 3 5
1 2 4
1 3 1
3 4 2
0 1000 1000 1000
3000 0 0 0


Output

50
0
3000

Solution (in CPP):

Solution:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 210

struct Info{
	Info(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

int V,N,M,L,num_Edge;
int source = 0,sink;

vector<Edge> G[NUM];
vector<Info> first_G[NUM];
bool used[NUM];
int min_dist[NUM][NUM];
int flow_dist[NUM];
int cheked_index[NUM];
int P[NUM],K[NUM];


void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1));
}

void bfs(int source){
	for(int i = 0; i < V; i++)flow_dist[i] = -1;
	queue<int> Q;
	flow_dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && flow_dist[e.to] < 0){
				flow_dist[e.to] = flow_dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow;

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && flow_dist[node_id] < flow_dist[e.to]){
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity));
			if(tmp_flow > 0){
				e.capacity -= tmp_flow;
				G[e.to][e.rev_index].capacity += tmp_flow;
				return tmp_flow;
			}
		}
	}
	return 0;
}


int max_flow(int source,int sink){
	int flow = 0,add;
	while(true){
		bfs(source);
		if(flow_dist[sink] < 0)break;
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){
			flow += add;
		}
	}
	return flow;
}


void func(){

	V = 2*N+2;
	sink = 2*N+1;

	for(int i = 0; i <= 2*N+1; i++){
		first_G[i].clear();
		G[i].clear();
	}

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			if(i != k){
				min_dist[i][k] = BIG_NUM;
			}else{
				min_dist[i][k] = 0;
			}
		}
	}

	int from,to,cost;
	for(int loop = 0; loop < M; loop++){
		scanf("%d %d %d",&from,&to,&cost);
		first_G[from].push_back(Info(to,cost));
		first_G[to].push_back(Info(from,cost));
		min_dist[from][to] = cost;
		min_dist[to][from] = cost;
	}

	for(int mid = 1; mid <= N; mid++){
		for(int start = 1; start <= N; start++){
			if(min_dist[start][mid] == BIG_NUM)continue;
			for(int end = 1; end <= N; end++){
				if(min_dist[mid][end] == BIG_NUM)continue;
				min_dist[start][end] = min(min_dist[start][end],min_dist[start][mid]+min_dist[mid][end]);
			}
		}
	}

	for(int i = 1; i <= N; i++)scanf("%d",&P[i]);
	for(int i = 1; i <= N; i++)scanf("%d",&K[i]);

	for(int i = 1; i <= N; i++){
		add_edge(source,i,P[i]);
	}

	for(int i = 1; i <= N; i++){
		add_edge(N+i,sink,K[i]);
	}

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			if(min_dist[i][k] < L){
				add_edge(i,N+k,P[i]);
			}
		}
	}

	printf("%d\n",max_flow(source,sink));
}

int main(){

	while(scanf("%d %d %d",&N,&M,&L) != EOF){
		func();
	}

	return 0;
}