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 <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge1
{
public:
    int to, cost;
    Edge1(){};
    Edge1(int to0, int cost0){to = to0; cost = cost0;}
};

class Edge2
{
public:
    int to, cap, rev;
    Edge2(){};
    Edge2(int to0, int cap0){to = to0; cap = cap0;}
    Edge2(int to0, int cap0, int rev0){to = to0; cap = cap0; rev = rev0;}
};

void shortestPath(const vector<vector<Edge1> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge1 e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

void shortestPath(const vector<vector<Edge1> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int maxFlow(const vector<vector<Edge2> >& edges0, int source, int sink)
{
    static vector<vector<Edge2> > edges;
    static vector<unsigned> index;
    static vector<int> level;
    static int n;

    class Func{
    public:
        static void bfs(int s){
            level.assign(n, -1);
            queue<int> q;
            level[s] = 0;
            q.push(s);
            while(!q.empty()){
                int v = q.front();
                q.pop();
                for(unsigned i=0; i<edges[v].size(); ++i){
                    Edge2& e = edges[v][i];
                    if(e.cap > 0 && level[e.to] < 0){
                        level[e.to] = level[v] + 1;
                        q.push(e.to);
                    }
                }
            }
        }
        static int dfs(int s, int t, int f){
            if(s == t)
                return f;
            for(unsigned& i=index[s]; i<edges[s].size(); ++i){
                Edge2& e = edges[s][i];
                if(e.cap > 0 && level[s] < level[e.to]){
                    int g = dfs(e.to, t, min(f, e.cap));
                    if(g > 0){
                        e.cap -= g;
                        edges[e.to][e.rev].cap += g;
                        return g;
                    }
                }
            }
            return 0;
        }
    };

    n = edges0.size();
    edges.assign(n, vector<Edge2>());
    for(int i=0; i<n; ++i){
        for(unsigned j=0; j<edges0[i].size(); ++j){
            const Edge2& e = edges0[i][j];
            edges[i].push_back(Edge2(e.to, e.cap, edges[e.to].size()));
            edges[e.to].push_back(Edge2(i, 0, edges[i].size()-1));
        }
    }

    int ret = 0;
    for(;;){
        Func::bfs(source);
        if(level[sink] < 0)
            return ret;
        index.assign(n, 0);
        int f;
        while((f = Func::dfs(source, sink, INT_MAX)) > 0)
            ret += f;
    }

    return 0;
}

int main()
{
    for(;;){
        int n, m, l;
        if(!(cin >> n >> m >> l))
            return 0;

        vector<vector<Edge1> > edges1(n);
        for(int i=0; i<m; ++i){
            int a, b, d;
            cin >> a >> b >> d;
            -- a;
            -- b;
            edges1[a].push_back(Edge1(b, d));
            edges1[b].push_back(Edge1(a, d));
        }

        vector<vector<int> > dist;
        shortestPath(edges1, dist);

        vector<vector<Edge2> > edges2(2*n+2);
        for(int i=0; i<n; ++i){
            int p;
            cin >> p;
            edges2[0].push_back(Edge2(i+1, p));
        }
        for(int i=0; i<n; ++i){
            int k;
            cin >> k;
            edges2[i+n+1].push_back(Edge2(2*n+1, k));
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(dist[i][j] < l)
                    edges2[i+1].push_back(Edge2(j+n+1, 1000000));
            }
        }

        cout << maxFlow(edges2, 0, 2*n+1) << endl;
    }
}