博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3371 Connect the Cities(prim算法)
阅读量:4676 次
发布时间:2019-06-09

本文共 1854 字,大约阅读时间需要 6 分钟。

题目链接:

Connect the Cities

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13628    Accepted Submission(s): 3679
Problem Description
In 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’t want to take too much money.  
 
Input
The first line contains the number of test cases.
Each test case starts with three integers: n, m and k. n (3 <= n <=500) stands for the number of survived cities, m (0 <= m <= 25000) stands for the number of roads you can choose to connect the cities and k (0 <= k <= 100) stands for the number of still connected cities.
To make it easy, the cities are signed from 1 to n.
Then follow m lines, each contains three integers p, q and c (0 <= c <= 1000), means it takes c to connect p and q.
Then follow k lines, each line starts with an integer t (2 <= t <= n) stands for the number of this connected cities. Then t integers follow stands for the id of these cities.
 
Output
For each case, output the least money you need to take, if it’s impossible, just output -1.
 
Sample Input
 
1 6 4 3 1 4 2 2 6 1 2 3 5 3 4 33 2 1 2 2 1 3 3 4 5 6
 
Sample Output
 
1

给出城市的数量 n 以及 需要相联的城市及所需花销,再给出已经相联的城市。求将所有城市相联的最小花销。

对于已经相联的城市,我们也将他们视为没有相联,并且将花销置为0.这样就和普通的最小生成树一样了,从头开始寻找就可以了

【源代码】

#include 
#include
#include
#include
#define INF 0xfffffffusing namespace std;int n,m,k;const int maxn = 510;struct node{ int v,len; node(int v=0, int len = 0):v(v),len(len){}};vector
G[maxn];int intree[maxn];int minDist[maxn];void init(){ for(int i=0;i

转载于:https://www.cnblogs.com/chaiwenjun000/p/5320979.html

你可能感兴趣的文章
多线程02
查看>>
Cyclone V 与 Avalon-MM资料整理——DE1-SOC学习笔记(1)
查看>>
.NET Core RabbitMQ探索(2)——RabbitMQ的Exchange
查看>>
Linux常用命令组合
查看>>
typeof与GetType
查看>>
海王星给你好看!FineUI v4.0公测版发布暨《你找BUG我送书》活动开始(活动已结束!)...
查看>>
Redhat72静默安装oracle11gR2
查看>>
2018-2019-1 20165318 20165326 实验五 通讯协议设计.md
查看>>
淘宝客做不下去怎么办?
查看>>
java开始时间结束时间取月份集合
查看>>
优化统计服务
查看>>
线上服务故障处理原则
查看>>
孪生兄弟状态模式与策略模式有什么区别,究竟该如何选择
查看>>
ヘルプ
查看>>
centos7 添加开机启动项
查看>>
luogu【P2745】[USACO5.3]窗体面积Window Area
查看>>
Codeforces 346D Robot Control(01BFS)
查看>>
CSS3学习笔记--media query 响应式布局
查看>>
NHibernate.3.0.Cookbook第四章第2节的翻译
查看>>
19.C#逐一介绍IEnumerable和IEnumerable<T>中的扩展方法(10.3-10.5)
查看>>