当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5545:The Battle of Guandu

题目描述
In the year of 200, two generals whose names are Cao Cao and Shao Yuan are fighting in Guandu. The battle of Guandu was a great battle and the two armies were fighting at $M$ different battlefields whose numbers were 1 to $M$. There were also $N$ villages nearby numbered from 1 to $N$. Cao Cao could train some warriors from those villages to strengthen his military. For village $i$, Cao Cao could only call for some number of warriors join the battlefield $x_{i}$. However, Shao Yuan's power was extremely strong at that time. So in order to protect themselves, village $i$ would also send equal number of warriors to battlefield $y_{i}$ and join the Yuan Shao's Army. If Cao Cao had called for one warrior from village $i$, he would have to pay $c_{i}$ units of money for the village. There was no need for Cao Cao to pay for the warriors who would join Shao Yuan's army. At the beginning, there were no warriors of both sides in every battlefield.

As one of greatest strategist at that time, Cao Cao was considering how to beat Shao Yuan. As we can image, the battlefields would have different level of importance $w_{i}$. Some of the battlefields with $w_{i}=2$ were very important, so Cao Cao had to guarantee that in these battlefields, the number of his warriors was greater than Shao Yuan's. And some of the battlefields with $w_{i}=1$ were not as important as before, so Cao Cao had to make sure that the number of his warriors was greater or equal to Shao Yuan's. The other battlefields with $w_{i}=0$ had no importance, so there were no restriction about the number of warriors in those battlefields. Now, given such conditions, could you help Cao Cao find the least number of money he had to pay to win the battlefield?
输入解释
The first line of the input gives the number of test cases, $T(1≤T≤30)$. $T$ test cases follow.

Each test case begins with two integers $N$ and $M(1≤N,M≤10^{5})$ in one line.

The second line contains $N$ integers separated by blanks. The $i_{th}$ integer $x_{i}(1≤x_{i}≤M)$ means Cao Cao could call for warriors from village $i$ to battlefield $x_{i}$.

The third line also contains $N$ integers separated by blanks. The $i_{th}$ integer $y_{i}(1≤y_{i}≤M)$ means if Cao Cao called some number of warriors from village $i$, there would be the same number of warriors join Shao Yuan's army and fight in battlefield $y_{i}$.

The next line contains $N$ integers separated by blanks. The $i_{th}$ integer $c_{i}(0≤c_{i}≤10^{5})$ means the number of money Cao Cao had to pay for each warrior from this village.

The last line contains $M$ integers separated by blanks. The $i_{th}$ number $w_{i}(w_{i}∈{0,1,2})$ means the importance level of $i_{th}$ battlefield.
输出解释
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the least amount of money that Cao Cao had to pay for all the warriors to win the battle. If he couldn't win, $y=-1$.
输入样例
2
2 3
2 3
1 1
1 1
0 1 2
1 1
1
1
1
2
输出样例
Case #1: 1
Case #2: -1
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5545

最后修改于 2020-10-25T23:23:38+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 65535/65535K(Java/Others)