博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdoj-3371-Connect the Cities【最小生成树】
阅读量:7050 次
发布时间:2019-06-28

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

Connect the Cities

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13299 Accepted Submission(s): 3618
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
Author
dandelion
Source
Recommend
lcy | We have carefully selected several similar problems for you:
#include
#include
#include
using namespace std;struct graph{ int a; int b; int cost;}G[ 25005];int root[505];int n,m;int find(int i){ if(root[i]==i) return i; return root[i]=find(root[i]);}void unio(int i,int j){ int t=find(i); int k=find(j); if(t<=k) root[k]=t; else root[t]=k; return ;}int cmp(graph u,graph v){ return u.cost
1) printf("-1\n"); else printf("%d\n",shortest); } return 0;}

转载地址:http://mypol.baihongyu.com/

你可能感兴趣的文章
牛人博客
查看>>
linux笔记_20150825_linux有什么好处
查看>>
各种实用工具的使用 学习
查看>>
MarkLight
查看>>
显示/隐藏Mac下的隐藏文件
查看>>
关于数字签名简要原理
查看>>
POJ-3565 Ants 空间点对不相交匹配-最小权值匹配
查看>>
第三次月考
查看>>
单例模式的理解与应用
查看>>
springmvc(一)
查看>>
Hibernate与 MyBatis的比较
查看>>
【51NOD-0】1137 矩阵乘法
查看>>
Android使用静默安装时碰见的问题
查看>>
MySQL单机多实例安装并配置主从复制
查看>>
awk调用shell命令的两种方法:system与print
查看>>
网络对抗技术 20164320 王浩 Exp 9 Web安全基础
查看>>
谷歌开源第二代机器学习系统 TensorFlow
查看>>
juqery模板 Templates
查看>>
eclipse 自动创建web.xml
查看>>
python 基础回顾2
查看>>