Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 ≤ i < k, and a1 = x and ak = y.

F - Arpa

Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.

Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.

Input

The first line contains integers nm and w (1  ≤  n  ≤  1000, F - Arpa, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000) — the weights of the Hoses.

The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106) — the beauties of the Hoses.

The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 ≤ xi, yi ≤ nxi ≠ yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.

Output

Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.

Examples

input

3 1 5
3 2 5
2 4 2
1 2

output

6

input

4 2 11
2 4 6 6
6 4 2 1
1 2
2 3

output

7

Note

在第一个示例中,有两个友谊组:Hoses {1, 2} 和​​ Hos {3}。 
最好的方法是选择第一组中的所有软管,它们的重量之和等于 5,它们的美度之和等于 6。 在第二个样本中,有两个友谊组:Hoses {1, 2, 3} 和 Hos {4}。
Mehrdad不能邀请第一组的所有Hoses,因为它们的总重量为12 > 11,

因此最好的方法是从第一组中选择第一个Hoses,从第二组中选择唯一一个。 总重量为8,总美感为7。

  

题目大意

有n个人,每个人都有颜值bi与体重wi。剧场的容量为W。n个人之间有m种关系表示两个人x,y为好朋友,好朋友的好朋友也是好朋友,

她们会形成一个小团体。每个小团体要么全部参加舞会,要么只参加一个人。保证总重量不超过W,剧场中的颜值最大能到多少
思路
     并查集+背包,先用并查集找到每个小团体,然后就是01背包问题了 ;

   背包问题处理时 使用一维dp数组, dp[w] 是体重W这个状态量下可以装的最大颜值
   这一块代码实现时,要找每个体重w可以装的最大颜值,先对小团体中找到最大颜值的
   那个放入背包。 最后判断小团体的总体重是否超过该w,未超过 此时w状态下的最大
   颜值为小团体总颜值;

 

代码实现

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int tree[1005];
int b[1005],w[1005];
int dp[1005];
int find(int x){
    if(tree[x]==x)
        return x;
    return tree[x]=find(tree[x]);
}

void change(int x,int y){
    int xx=find(x);
    int yy=find(y);
    if(xx!=yy)
        tree[xx]=yy;
}

int main()
{
    vector<int>group[1005];
   int n,m,W;
   cin>>n>>m>>W;
   for(int i=1;i<=n;i++)
    cin>>w[i];
   for(int i=1;i<=n;i++)
    cin>>b[i];
    for(int i=1;i<=n;i++)
        tree[i]=i;
   for(int i=0;i<m;i++){ //使用并查集处理数据
    int a,b;
    cin>>a>>b;
    change(a,b);
   }for(int i=1;i<=n;i++)
    group[find(i)].push_back(i);  //向group数组中存 根节点 相同的子节点(小团体化)
   memset(dp,0,sizeof(dp));
 for(int i=1;i<=n;++i){
            if(find(i)!=i)    //先判断是不是根节点
                continue;
            for(int j=W;j>=0;j--){ //01背包使用一维数组优化时,体重w要从大向小写
                int sumw=0, sumb=0;
                for(int k=0;k<group[i].size();++k){
                    sumw+=w[group[i][k]]; //体重和
                    sumb+=b[group[i][k]]; //颜值和
                    if(j>=w[group[i][k]])
                        dp[j]=max(dp[j], dp[j-w[group[i][k]]] + b[group[i][k]]);//先将小团体中最大颜值的放入体重j状态中
                }
                if(j>=sumw)   //判断此时的体重j是否大于等于小团体总体重
                    dp[j]=max(dp[j],dp[j-sumw] + sumb);
            }
        }
   cout<<dp[W]<<endl;
    return 0;
}