


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Build The Electric SystemTime Limit: 1 Second Memory Limit: 32768 KB In last winter, there was a big snow storm in South China. The electric system was damaged seriously. Lots of power lines were broken and lots of villages lost contact with the main power grid. The government wants to reconstruct the electric system as soon as possible. So, as a professional programmer, you are asked to write a program to calculate the minimum cost to reconstruct the power lines to make sure theres at least one way between every two villages. InputStandard input will contain multiple test cases. The first line of the input is a single integer T (1 = T = 50) which is the number of test cases. And it will be followed by T consecutive test cases. In each test case, the first line contains two positive integers N and E (2 = N = 500, N = E = N * (N - 1) / 2), representing the number of the villages and the number of the original power lines between villages. There follow E lines, and each of them contains three integers, A, B, K (0 = A, B N, 0 = K 1000). A and B respectively means the index of the starting village and ending village of the power line. If K is 0, it means this line still works fine after the snow storm. If K is a positive integer, it means this line will cost K to reconstruct. There will be at most one line between any two villages, and there will not be any line from one village to itself. OutputFor each test case in the input, theres only one line that contains the minimum cost to recover the electric system to make sure that theres at least one way between every two villages. Sample Input13 30 1 50 2 01 2 9Sample Output5#include /直接bfs无向图mstint a125000,b125000,k125000;int village501; /村庄的出现与否 -1 or 0void pai_xu(int e) /k 递增 int i,j,temp; for(i=0;ie-1;i+) for(j=i+1;jkj) temp=ki;ki=kj;kj=temp; temp=ai;ai=aj;aj=temp; temp=bi;bi=bj;bj=temp; int main() int i,t,j,h,sum,n,e; while(scanf(%d,&t)!=EOF) for(i=0;it;i+) scanf(%d%d,&n,&e); for(j=0;je;j+) scanf(%d%d%d,&aj,&bj,&kj); for(j=0;jn;j+) villagej=0; pai_xu(e); villagea0=villageb0=-1; sum=k0; for(j=1;jn;j+) for(h=1;he;h+) if(villageah!=-1&vil
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 衡水市人民医院人工智能在医疗信息化中的应用试题
- 沧州市中医院免疫抑制剂血药浓度监测考核
- 北京市中医院内分泌专科护士资格认证考试
- 沧州市人民医院肌电图报告解读考核
- 张家口市人民医院护理压力管理考核
- 大学课件中的影视元素
- 2025贵州省人民医院第十三届贵州人博会引进人才10人考前自测高频考点模拟试题及答案详解一套
- 衡水市人民医院腰椎经椎间孔减压融合术TLIF技能考核
- 2025春季新疆石河子大学第一附属医院、石河子大学附属中医医院(兵团中医医院)校园招聘10人模拟试卷带答案详解
- 2025中心医院妇科MRI影像判读考核
- 军品配套项目管理办法
- 《大中型企业安全生产标准化管理体系要求》
- 甲状腺结节术后护理
- TCSF00782023森林草原消防无人机巡护作业技术规程
- DB62∕T 4964-2024 地质灾害精细调查技术规范
- 水泥标准培训课件
- 2025秋二年级上册语文上课课件 5 去外婆家
- 2025年七一党课-作风建设永远在路上学习教育党课
- 2025年《互联网销售》课程标准
- 4《公民的基本权利和义务》第一课时 公开课一等奖创新教案
- 家博会合同协议书
评论
0/150
提交评论