编程介的小学生 2019-08-24 22:13 采纳率: 20.5%
浏览 102

用程序正确解答 Computer Assembling

Problem Description
XiaoA is becoming more and more unsatisfied with his computer since he is learning hacker technologies these days but his computer always fails whenever he changes the configurations of the NIC. He buys a new NIC but the motherboard doesn’t recognize it. He then pays for a motherboard from the same company as the NIC. This time the display card 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 has to buy n components. Two companies are finally chosen after he searches the web. They both offer all the n components but the prices may vary. There are some pairs of components such that if XiaoA buys them from different companies he has to spend an additional fee to buy adapters to avoid the collision problem.
XiaoA wants to spend as little as possible. Please tell him the minimum dollars he has to pay.

Input
There are multiple test cases.
For each test case, the first line contains two integers n and m(1<=n<=500, 0<=m<=n*(n-1)/2), indicating the number of components and the number of pairs. The components are conveniently numbered from 1 to n and all pairs are distinct. The next two lines both have n integers(in the range [1, 200]), describing the price in dollar for each component they offer in 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 from different companies, he has to spend another c dollars for an adapter.
Proceed to the end of file.

Output
For each test case, 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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler