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 <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>

using namespace std;

struct flow_graph{
    int MAX_V,E,s,t,head,tail;
    int *cap,*to,*next,*last,*dist,*q,*now;
    
    flow_graph(){}
    
    flow_graph(int V, int MAX_E){
        MAX_V = V; E = 0;
        cap = new int[2*MAX_E], to = new int[2*MAX_E], next = new int[2*MAX_E];
        last = new int[MAX_V], q = new int[MAX_V];
        dist = new int[MAX_V], now = new int[MAX_V];
        fill(last,last+MAX_V,-1);
    }
    
    void clear(){
        fill(last,last+MAX_V,-1);
        E = 0;
    }
    
    void add_edge(int u, int v, int uv){
        to[E] = v, cap[E] = uv, next[E] = last[u]; last[u] = E++;
        to[E] = u, cap[E] = 0, next[E] = last[v]; last[v] = E++;
    }
  
    bool bfs(){
        fill(dist,dist+MAX_V,-1);
        head = tail = 0;
    
        q[tail] = t; ++tail;
        dist[t] = 0;
    
        while(head<tail){
            int v = q[head]; ++head;
            
            for(int e = last[v];e!=-1;e = next[e]){
                if(cap[e^1]>0 && dist[to[e]]==-1){
                    q[tail] = to[e]; ++tail;
                    dist[to[e]] = dist[v]+1;
                }
            }
        }
        
        return dist[s]!=-1;
    }
  
    int dfs(int v, int f){
        if(v==t) return f;
    
        for(int &e = now[v];e!=-1;e = next[e]){
            if(cap[e]>0 && dist[to[e]]==dist[v]-1){
                int ret = dfs(to[e],min(f,cap[e]));
        
                if(ret>0){
                    cap[e] -= ret;
                    cap[e^1] += ret;
                    return ret;
                }
            }
        }
    
        return 0;
    }
  
    int max_flow(int source, int sink){
        s = source; t = sink;
        int f = 0,df;
    
        while(bfs()){
            for(int i = 0;i<MAX_V;++i) now[i] = last[i];
      
            while(true){
                df = dfs(s,INT_MAX);
                if(df==0) break;
                f += df;
            }
        }
    
        return f;
    }
}G(202,100*100 + 100*2);

int main(){
    int N,M,L;
    int dist[100][100];
    
    while(scanf("%d %d %d",&N,&M,&L) == 3){
        for(int i = 0;i < N;++i){
            dist[i][i] = 0;
            
            for(int j = i + 1;j < N;++j)
                dist[i][j] = dist[j][i] = L;
        }
        
        for(int i = 0,u,v,d;i < M;++i){
            scanf("%d %d %d",&u,&v,&d);
            --u; --v;
            
            dist[u][v] = min(dist[u][v],d);
            dist[v][u] = dist[u][v];
        }
        
        for(int k = 0;k < N;++k)
            for(int i = 0;i < N;++i)
                for(int j = 0;j < N;++j)
                    dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
        
        G.clear();
        
        for(int i = 0,p;i < N;++i){
            scanf("%d",&p);
            G.add_edge(0,1 + i,p);
        }
        
        for(int i = 0,k;i < N;++i){
            scanf("%d",&k);
            G.add_edge(1 + N + i,1 + 2*N,k);
        }
        
        for(int i = 0;i < N;++i)
            for(int j = 0;j < N;++j)
                if(dist[i][j] < L)
                    G.add_edge(1 + i,1 + N + j,1000000);
        
        printf("%d\n",G.max_flow(0,1 + 2*N));
    }
    
    return 0;
}