#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

typedef int Weight;
const Weight INF = 1e8;

struct Edge {
    int src, dst;
    Weight weight;
    int rev;
    Edge(int f, int t, Weight c, int rev = 0) :
        src(f), dst(t), weight(c), rev(rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void AddEdge(Graph &g, int s, int dst, Weight cap){
    g[s].push_back(Edge(s, dst, cap, g[dst].size()));
    g[dst].push_back(Edge(dst, s, 0, g[s].size()-1));
}

void Bfs(const Graph &g, vector<int> &level, int s){
    level[s]=0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (auto &e : g[v]) {
            if(e.weight > 0 && level[e.dst] < 0){
                level[e.dst] = level[v] + 1;
                que.push(e.dst);
            }
        }
    }
}
Weight Dfs(Graph &g, vector<int> &level, vector<int> &iter,
           int v, int t, Weight flow) {
    if(v == t)
        return flow;
    for (int &i = iter[v], N = g[v].size(); i < N; ++i) {
        Edge &e = g[v][i];

        if(e.weight > 0 && level[v] < level[e.dst]){
            Weight d = Dfs(g, level, iter, e.dst, t, min(flow, e.weight));
            if(d > 0){
                e.weight -= d;
                g[e.dst][e.rev].weight += d;
                return d;
            }
        }
    }
    return 0;
}

Weight Dinic(Graph &g, int s, int t){
    Weight flow = 0;

    while(true){
        vector<int> level(g.size(), -1);
        vector<int> iter(g.size(), 0);
        Bfs(g, level, s);

        if(level[t] < 0)
            break; // もう流せない
        Weight f = 0;
        while((f = Dfs(g, level, iter, s, t, INF)) > 0)
            flow += f;
    }
    return flow;
}

void WarshallFloyd(Matrix &dist) {
    int n = dist.size();
    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]);
}

int main()
{
    int N, M, L, A, B, D, P, K;

    while (cin >> N >> M >> L) {
        Matrix dist(N, Array(N, INF));

        for (int i = 0; i < M; ++i) {
            cin >> A >> B >> D;
            dist[A - 1][B - 1] = dist[B - 1][A - 1] = D;
        }
        for (int i = 0; i < N; ++i)
            dist[i][i] = 0;

        WarshallFloyd(dist);

        Graph g(2 * N + 2);
        int s = 2 * N, t = 2 * N + 1;

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (i == j)
                    AddEdge(g, i, i + N, INF);
                else if (dist[i][j] < L)
                    AddEdge(g, i, j + N, INF);
            }
        }

        for (int i = 0; i < N; ++i) {
            cin >> P;
            AddEdge(g, s, i, P);
        }
        for (int i = 0; i < N; ++i) {
            cin >> K;
            AddEdge(g, i + N, t, K);
        }

        cout << Dinic(g, s, t) << endl;
    }

    return 0;
}
### Prompt

Construct a CPP code solution to the problem outlined:

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

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

typedef int Weight;
const Weight INF = 1e8;

struct Edge {
    int src, dst;
    Weight weight;
    int rev;
    Edge(int f, int t, Weight c, int rev = 0) :
        src(f), dst(t), weight(c), rev(rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void AddEdge(Graph &g, int s, int dst, Weight cap){
    g[s].push_back(Edge(s, dst, cap, g[dst].size()));
    g[dst].push_back(Edge(dst, s, 0, g[s].size()-1));
}

void Bfs(const Graph &g, vector<int> &level, int s){
    level[s]=0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (auto &e : g[v]) {
            if(e.weight > 0 && level[e.dst] < 0){
                level[e.dst] = level[v] + 1;
                que.push(e.dst);
            }
        }
    }
}
Weight Dfs(Graph &g, vector<int> &level, vector<int> &iter,
           int v, int t, Weight flow) {
    if(v == t)
        return flow;
    for (int &i = iter[v], N = g[v].size(); i < N; ++i) {
        Edge &e = g[v][i];

        if(e.weight > 0 && level[v] < level[e.dst]){
            Weight d = Dfs(g, level, iter, e.dst, t, min(flow, e.weight));
            if(d > 0){
                e.weight -= d;
                g[e.dst][e.rev].weight += d;
                return d;
            }
        }
    }
    return 0;
}

Weight Dinic(Graph &g, int s, int t){
    Weight flow = 0;

    while(true){
        vector<int> level(g.size(), -1);
        vector<int> iter(g.size(), 0);
        Bfs(g, level, s);

        if(level[t] < 0)
            break; // もう流せない
        Weight f = 0;
        while((f = Dfs(g, level, iter, s, t, INF)) > 0)
            flow += f;
    }
    return flow;
}

void WarshallFloyd(Matrix &dist) {
    int n = dist.size();
    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]);
}

int main()
{
    int N, M, L, A, B, D, P, K;

    while (cin >> N >> M >> L) {
        Matrix dist(N, Array(N, INF));

        for (int i = 0; i < M; ++i) {
            cin >> A >> B >> D;
            dist[A - 1][B - 1] = dist[B - 1][A - 1] = D;
        }
        for (int i = 0; i < N; ++i)
            dist[i][i] = 0;

        WarshallFloyd(dist);

        Graph g(2 * N + 2);
        int s = 2 * N, t = 2 * N + 1;

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (i == j)
                    AddEdge(g, i, i + N, INF);
                else if (dist[i][j] < L)
                    AddEdge(g, i, j + N, INF);
            }
        }

        for (int i = 0; i < N; ++i) {
            cin >> P;
            AddEdge(g, s, i, P);
        }
        for (int i = 0; i < N; ++i) {
            cin >> K;
            AddEdge(g, i + N, t, K);
        }

        cout << Dinic(g, s, t) << endl;
    }

    return 0;
}
```