A10751 | Arpa's weak amphitheater and Mehrdad's valuable
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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}<=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.
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>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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted