csu 1965
2017-07-24 10:13
302 查看
Description
You are a boss who has N employers. One day, you have a message and you want to tell it to M employers of yours. As you are a funny man, you want to choose some of the M employers and tell them the message, and then let them tell other employers so that all the M know the message (you don't care whether the other N − M employers know the message or not). Employers who know the message can tell it to anyone else. The ith employer telling the jth employer causes a cost of Cij and you want to know what the minimal total cost is.Input
The input data consists of several cases. The first line contains one integer, T, indicating the number of test cases. For each test case, the first line contains two integers, N (10 ≤ N ≤ 50) and M (5 ≤ M ≤ 10), described above. The employers are numbered from 1. In the next N lines, each line contains N integers. The jth integer in the ith line is Cij (1 ≤ Cij ≤ 1000, Cii = 0, Cij = Cji). In the next line, there are 2 × M integers. The 2 × i − 1th integer is the index of the ith employer who you want to know the message. The 2 × ith is the cost for you to tell him the message. All cost values are between 1 and 1000.Output
For each test case, print one integer in one line, W, indicating the mininal total cost.Sample Input
1 10 5 0 42 468 501 479 706 492 605 719 668 42 0 335 170 359 146 996 903 896 300 468 335 0 725 963 282 943 154 448 36 501 170 725 0 465 828 828 293 727 895 479 359 963 465 0 962 437 383 772 704 706 146 282 828 962 0 392 422 539 812 492 996 943 828 437 392 0 717 870 323 605 903 154 293 383 422 717 0 913 334 719 896 448 727 772 539 870 913 0 674 668 300 36 895 704 812 323 334 674 0 5 142 2 54 9 148 3 158 8 60
Sample Output
558
Hint
现场只有一个队做出来了,想了半天没做出来。首先是费用流,保证每个点都被访问,那么会使得所有点都有一个连到源点,汇点,那么他们的权值一定至少全被加起来了。
最短路,枚举选哪些点,跑到其他所有点,sum + dist[v],会有重复路径,还要把所有重复路径的点删掉。太难搞咯~~~
相关文章推荐
- CSU 1965(斯坦纳树)
- CSUOJ 1219: 建食堂
- “CSU_BMW正式组建纪念赛”解题报告
- csu 1004 Xi and Bo
- csu-1212 快排
- CSU5月月赛
- CSU 1097 Gifts with different style
- csu oj 1339: 最后一滴血
- csuoj1303(将循环小数转化为分数)
- csu 10月 月赛 D 题 CX and girls
- csu 1356 Catch bfs(vector)
- CSU_1414 Query On a Tree BFS序+DFS时间戳进行预处理
- 1965: [Ahoi2005]SHUFFLE 洗牌 - BZOJ
- CSU-ACM暑假集训基础组训练赛(1) A - Problem A
- CSU 1126 DFS前缀和
- csu1424_Qz’s Maximum All One Square
- CSU-1401: 插入排序
- CSU
- csu 1335 高桥和低桥(树状数组+二分)
- CSU 1339: 最后一滴血(模拟啊 湖南省第九届大学生计算机程序设计竞赛)