Codeforces Round 383 (Div. 1)
B
Arpa's weak amphitheater and Mehrdad's valuable Hoses
Codeforces
1600
原题
← AC →
翻译中…

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

翻译中…

image

翻译中…

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 $*n*$, $*m*$ and $*w*$ ($1  ≤  *n*  ≤  1000$, image, $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.

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
3 1 5
3 2 5
2 4 2
1 2
Output #1
6
InputCopy OutputCopy
Input #2
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output #2
7
InputCopy OutputCopy
题目信息
题号
741B
时间限制
1 s
内存限制
256 MB
标签
DFS 及类似
动态规划
并查集

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。