hdu3526(最小费用流)

Description

Xiao A isbecoming more and more unsatisfied with his computer since he is learninghacker(黑客技术) technologiesthese days but his computer always fails whenever he changes the configurationsof the NIC. He buys a new NIC but the motherboard doesn’t recognize it. He thenpays for a motherboard from the same company as the NIC. This time the displaycard is in collision with the motherboard so he cannot even start his computer. 
After days of affliction, XiaoA decides to assemble a computer himself. He hasto buy n components. Two companies are finally chosen after he searches theweb. They both offer all the n components but the prices may vary. There aresome pairs of components such that if XiaoA buys them from different companieshe has to spend an additional fee to buy adapters to avoid the collisionproblem. 
XiaoA wants to spend as little as possible. Please tell him the minimum dollarshe has to pay. 

Input

There aremultiple test cases. 
For each test case, the first line contains two integers n andm(1<=n<=500, 0<=m<=n*(n-1)/2), indicating the number of componentsand the number of pairs. The components are conveniently numbered from 1 to nand all pairs are distinct. The next two lines both have n integers(in therange [1, 200]), describing the price in dollar for each component they offerin order. The next m lines contain three integers i, j and c(1<=i, j<=n,i!=j, 1<=c<=200) each, indicating that if he buys component i and j fromdifferent companies, he has to spend another c dollars for an adapter. 
Proceed to the end of file. 

Output

For each testcase, print the minimum cost on a single line.

Sample Input

5 3

2 3 4 5 2

1 5 3 6 4

1 2 3

2 3 5

3 4 2

Sample Output

16

题意:自从A这些天一直在学习黑客技术,她对自己的电脑越来越不满意无论她怎么改变自己电脑网络服务中心的配置她的电脑总是不工作,她买了一个新的网络服务中心但是和主板不兼容,然后她从买NIC的公司买了一个主板,这次是显卡不兼容甚至开机不了,苦恼了几天之后,A决定自己配置电脑,她从网上搜索最后决定有两家公司可以提供所有的硬件,这两家公司提供的硬件价格各异,如果A从不同公司买一些部件,她不得不花费额外的费用去买适配器由此避免硬件冲突,A想尽可能话费最少的钱,请你帮她。。。

         输入:

                  多组测试数据,对于每组测试数据,首先一行包含n、m分别表示部件的数量和配对的数量,配件的数量是从1到n并且所有的配对是以区分的,接下来的两行有n个数字,描述每一个部件的价格按顺序排列,接下来的m行包含3个数字i、i、c,其中i、j表示从不同的公司获得,她不得不话费C美元买一个适配器,运行已文件结束。

代码:

         翻译完后并没有思路…,看网上是最小费用流问题

你可能感兴趣的:(-----ACM水题-----,ACM算法入门)