CF741B.Arpa's weak amphitheater and Mehrdad's valuable Hoses
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 < k, and _a_1 = x and a__k = y.

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.
提醒一下,Arpa 国度里的女孩们都非常优秀。
Mehrdad 想邀请一些 Hoses(人名,此处保留原词)到宫殿举办一场舞会。每位 Hos 有一定的体重 wi 和一定的美貌值 bi。此外,每位 Hos 可能拥有一些朋友。所有 Hoses 被划分为若干个友谊团体。两个 Hos x 和 y 属于同一友谊团体,当且仅当存在一个 Hos 序列 a1,a2,…,ak,使得对每个 1≤i<k,ai 与 ai+1 是朋友,且 a1=x、ak=y。

Arpa 允许 Mehrdad 在本次舞会中使用宫殿的圆形剧场(amphitheater)。Arpa 的圆形剧场最多可承载总重为 w 的人。
Mehrdad 非常贪心,他希望邀请一组 Hoses,使其总体重不超过 w,且总美貌值尽可能大。此外,对于每个友谊团体,他要么全部邀请该团体中的所有 Hoses,要么至多只邀请其中一人;否则,某些 Hoses 会受到伤害。请帮 Mehrdad 找出在无人受伤、且总重量不超过 w 的前提下,所能邀请的 Hoses 的最大总美貌值。
输入格式
The first line contains integers n, m and w (1 ≤ n ≤ 1000,
, 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 ≤ 106) — 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.
第一行包含三个整数 n、m 和 w(1≤n≤1000,
,1≤w≤1000)——分别表示 Hoses 的数量、朋友对的数量以及被邀请者总重量的最大值。
第二行包含 n 个整数 w1,w2,…,wn(1≤wi≤1000)——表示各个 Hose 的重量。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤106)——表示各个 Hose 的美貌值。
接下来的 m 行描述朋友关系,其中第 i 行包含两个整数 xi 和 yi(1≤xi,yi≤n,且 xi=yi),表示 Hose xi 与 Hose yi 是朋友。注意:朋友关系是双向的。所有对 (xi,yi) 均互不相同。
输出格式
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.
输出 Mehrdad 可以邀请的 Hoses 的最大可能总美丽值,使得没有人受伤且总重量不超过 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 > 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.
在第一个样例中,存在两个朋友群:Hoses {1, 2} 和 Hos {3}。最优方案是选择第一个群中的全部 Hoses,其总重量为 5,总美丽值为 6。
在第二个样例中,存在两个朋友群:Hoses {1, 2, 3} 和 Hos {4}。Mehrdad 无法邀请第一个群中的全部 Hoses,因为它们的总重量为 12 > 11;因此最优方案是选择第一个群中的第一个 Hos 和第二个群中的唯一一个 Hos。总重量为 8,总美丽值为 7。
输入解题思路,AI测评打分。不知道怎么写?