Arpa's weak amphitheater and Mehrdad's valuable

题意翻译

题目描述: 有 $n$ 个人 $(1\le n\le1000)$。每个人有一个重量 $w_i(1\le w_i\le 1000)$ 和一个魅力值 $b_i(1\le b_i\le 10^6)$。 $n$ 个人之间有 $m(1\le m\le\min(\frac{n\times(n-1)}{2}, 10^5))$ 个关系。第 $i$ 个关系由两个数字 $x_i$ 和 $y_i$ 组成,表示第 $x_i$ 个人和第 $y_i$ 个人是朋友,朋友关系是双向的。 已知若 $a$ 和 $b$ 是朋友,$b$ 和 $c$ 是朋友,则 $a$ 和 $c$ 是朋友。 现在 Mehrdad 要邀请一些人来到派对,使这些人的重量总和不超过 $w\ (1\le w\le1000)$,且魅力值总和尽量大。同一个朋友圈里的人,只能邀请其中的一个人,或者全部人,或者一个人也不邀请。 输入格式: 第一行,三个整数 $n,m,w$ 第二行,$n$ 个整数 $w_1,w_2,\cdots,w_n$ 第三行,$n$ 个整数 $b_1,b_2,\cdots,b_n$ 接下来 $m$ 行,每行表示一个关系,第 $i$ 行有两个整数 $x_i$ 和 $y_i$。每一组朋友关系都是不同的。 输出格式: 一行,表示最大的魅力值总和。

题目描述

Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight $ w_{i} $ and some beauty $ b_{i} $ . 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 $ a_{1},a_{2},...,a_{k} $ such that $ a_{i} $ and $ a_{i+1} $ are friends for each $ 1<=i&lt;k $ , and $ a_{1}=x $ and $ a_{k}=y $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF741B/728ee3bf7100b300a410e67b3d6aa62d4d0fdc8c.png)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 $ .

输入输出格式

输入格式


The first line contains integers $ n $ , $ m $ and $ w $ ( $ 1<=n<=1000 $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF741B/6b30ec73a9fc95e93293c9f43a9771cf5bc89189.png), $ 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 $ w_{1},w_{2},...,w_{n} $ ( $ 1<=w_{i}<=1000 $ ) — the weights of the Hoses. The third line contains $ n $ integers $ b_{1},b_{2},...,b_{n} $ ( $ 1<=b_{i}<=10^{6} $ ) — the beauties of the Hoses. The next $ m $ lines contain pairs of friends, the $ i $ -th of them contains two integers $ x_{i} $ and $ y_{i} $ ( $ 1<=x_{i},y_{i}<=n $ , $ x_{i}≠y_{i} $ ), meaning that Hoses $ x_{i} $ and $ y_{i} $ are friends. Note that friendship is bidirectional. All pairs $ (x_{i},y_{i}) $ are distinct.

输出格式


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 $ .

输入输出样例

输入样例 #1

3 1 5
3 2 5
2 4 2
1 2

输出样例 #1

6

输入样例 #2

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

输出样例 #2

7

说明

In the first sample there are two friendship groups: Hoses $ {1,2} $ and Hos $ {3} $ . The best way is to choose all of Hoses in the first group, sum of their weights is equal to $ 5 $ and sum of their beauty is $ 6 $ . In the second sample there are two friendship groups: Hoses $ {1,2,3} $ and Hos $ {4} $ . Mehrdad can't invite all the Hoses from the first group because their total weight is $ 12&gt;11 $ , thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be $ 8 $ , and the total beauty will be $ 7 $ .