Connect the Cities--hdoj
Connect the Cities
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 5
again, but they don’t want to take too much money.
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.
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
1
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0xfffffff
int map[505][505],mark[505],num[505];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,j,m,n,k,a,b,c;
scanf("%d%d%d",&n,&m,&k);
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
map[i][j]=map[j][i]=INF;
for(i=0;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])
map[a][b]=map[b][a]=c;
}
for(i=0;i<k;i++)
{
scanf("%d",&a);
for(j=0;j<a;j++)
scanf("%d",&num[j]);
for(j=0;j<a;j++)
for(int jj=j+1;jj<a;jj++)
{
map[num[j]][num[jj]]=map[num[jj]][num[j]]=0;
}
}
int sum=0,flog;
memset(mark,0,sizeof(mark));
for(i=2;i<=n;i++)
{
int min=INF;
flog=-1;
for(j=2;j<=n;j++)
{
if(!mark[j]&&map[1][j]<min)
{
flog=j;
min=map[1][j];
}
}
if(flog==-1) break;
mark[flog]=1;
sum+=map[1][flog];
for(j=2;j<=n;j++)
{
if(!mark[j]&&map[1][j]>map[flog][j])
map[1][j]=map[flog][j];
}
}
if(i>n)
printf("%d\n",sum);
else printf("-1\n");
}
return 0;
}
Connect the Cities--hdoj的更多相关文章
- hdoj 3371 Connect the Cities
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 3371 kruscal/prim求最小生成树 Connect the Cities 大坑大坑
这个时间短 700多s #include<stdio.h> #include<string.h> #include<iostream> #include<al ...
- Connect the Cities(prim)用prim都可能超时,交了20几发卡时过的
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3371 Connect the Cities(prim算法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3371 Problem Description In 2100, since the sea leve ...
- hdu oj 3371 Connect the Cities (最小生成树)
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu3371 Connect the Cities (MST)
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Connect the Cities[HDU3371]
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Connect the Cities(MST prim)
Connect the Cities Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 3371 Connect the Cities
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3371 Connect the Cities Description In 2100, since th ...
- Connect the Cities(prime)
Connect the Cities Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
随机推荐
- 复习java基础第二天(异常处理)
一.常见的异常类型: public class TestException { public static void main(String[] args) { int i = 10; //数学异常: ...
- Asp.Net Core 中利用QuartzHostedService 实现 Quartz 注入依赖 (DI)
QuartzHostedService 是一个用来在Asp.Net Core 中实现 Quartz 的任务注入依赖的nuget 包: 基本示例如下: using System; using Syst ...
- vue点击实现 路由的跳转
点击按钮实现路由的跳转 <div @click="gotoMenu">按钮</div> 实现跳转 methods: { gotoMenu(){ //跳转到上 ...
- eas之编码规则&单据转换规则
*当在企业建模中没有要显示的项目的话,则从包更新到系统树然后选择到规则定义,对申请单新增规则. 企业建模--业务规则-规则定义组织优先 多组织有先 集团优先固定值 显示格式PUR ..系统日期 2 ...
- Vue.js大总结
最近回顾了一下Vue.js的基础知识,把认为重要的几个点简单的罗列了出来 vue渐进式的理解 vue可以开发很多插件,可以把很多插件组合到一起,渐进的增加vue的功能 update beforeUpd ...
- Monkey日志中如何找错误
无响应问题可以在日志中搜索 “ANR” ,崩溃问题搜索 “CRASH” ,内存泄露问题搜索"GC"(需进一步分析),异常问题搜索 “Exception” monkey执行时未 ...
- <a>标签中的href伪协议 标签: html 2016-12-24 22:38 365人阅读 评论(0)
<a id="jsPswEdit" class="set-item" href="javascript:;">修改密码</ ...
- 32.es读请示内部分发原理
当客户端发送一次读请求时,大致会经过以下几个步骤 1.客户端发送一个请求过去,es的一个node接收到这个请求(随机的node),这个node就被es内部分配成coordinating node(协调 ...
- 使用VS Code断点调试PHP
vs code 使用一款杰出的轻量级代码编辑器,其中的插件工具不胜枚举而且还在不断增加.使用 vs code 调试 php 代码更是方便简洁,下面我们来一起看一下. 1. 安装 XDebug 扩展 调 ...
- 域名和ip、端口的关系
背景:新建一个项目,属于RPC服务,调用时需要ip+端口. 在工单系统里走流程,强制填写域名.之前也操作过,感觉域名不重要.我本来需要填写ip+端口,你给整个域名,那我端口往哪写?(一直以为域名=ip ...