Connect the Cities(prime)
Connect the Cities
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 3
#include<stdio.h>
#include<string.h>
const int INF=0x3f3f3f3f;
const int MAXN=;
int n,answer;
int map[MAXN][MAXN],vis[MAXN],low[MAXN];
void prime(){
memset(vis,,sizeof(vis));
int k,temp,flot=;
vis[]=;
for(int i=;i<=n;i++)
low[i]=map[][i];
for(int i=;i<=n;i++){
temp=INF;
for(int j=;j<=n;j++){
if(!vis[j]&&temp>low[j])temp=low[k=j];
}
if(temp==INF){
if(flot==n)printf("%d\n",answer);
else puts("-1");
// printf("%d %d\n",n,flot);
break;
}
vis[k]=;
flot++;
answer+=temp;
for(int j=;j<=n;j++)
if(!vis[j]&&low[j]>map[k][j])//ÎÞÓд³É<´íÁ˰ëÌ죻£»£»
low[j]=map[k][j];
}
}
int main(){
int T,m,k,a,b,c;
scanf("%d",&T);
while(T--){answer=;
memset(map,INF,sizeof(map));
scanf("%d%d%d",&n,&m,&k);
while(m--){
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])
map[a][b]=map[b][a]=c;//printf("...%d %d %d\n",a,b,c);
}
while(k--){
scanf("%d",&a);
for(int i=;i<a;i++){
scanf("%d",&b);
if(!i)c=b;
if(c!=b)
map[c][b]=map[b][c]=;//printf("***%d %d\n",b,c);
}
}
prime();
}
return ;
}
Connect the Cities(prime)的更多相关文章
- hdoj 3371 Connect the Cities
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 kruscal/prim求最小生成树 Connect the Cities 大坑大坑
这个时间短 700多s #include<stdio.h> #include<string.h> #include<iostream> #include<al ...
- 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(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 ...
- Connect the Cities(hdu3371)并查集(附测试数据)
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 3371 Connect the Cities(最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3371 984ms风险飘过~~~ /************************************ ...
随机推荐
- 二十六、Jcreator使用初步
摘自http://blog.csdn.net/liujun13579/article/details/7751464 二十六.Jcreator使用初步 Jcreator是一个小巧灵活的Java开发工具 ...
- The Java™ Tutorials下载地址
1.The Java™ Tutorials下载地址: http://www.oracle.com/technetwork/java/javase/java-tutorial-downloads-200 ...
- Struts2+Spring集成合并
前边单独总结了Struts2,Spring和Ibaits框架了,那么怎么结合使用呢?这次先来看一下Sturts2和Spring的集成合并.其实挺简单的,就是导入各自的jar包以及连接彼此的jar包,分 ...
- Spring整合Quartz
目录[-] 一.Spring创建JobDetail的两种方式 二.整合方式一示例步骤 1.将spring核心jar包.quartz.jar和Spring-context-support.jar导入类路 ...
- JavaWeb——文件上传和下载
在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功能的实现. 对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用 ...
- zb的生日(暴搜dfs)
zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 今天是阴历七月初五,acm队员zb的生日.zb正在和C小加.never在武汉集训.他想给这两位兄弟买点什么 ...
- 基于angularJS和requireJS的前端架构
1.概要描述 1.1.angularJS描述:angularJS是可以用来构建WEB应用的,WEB应用中的一种端对端的完整解决方案.通过开发者呈现一个更高层次的抽象来简化应用的开发.最适合的就是用它来 ...
- Unity NGUI 血条制作
NGUI 血条制作步骤 实现过程: 模拟血条的变化当点击按钮Button是血条会实时发生变化. 1.向Unity中导入NGUI2.6.3.unitypackage 点击create your ui 后 ...
- Sybase配置数据库参数
Sybase配置数据库参数参数配置的两种方法:sp_configure ‘参数名称’,参数值修改参数文件(如:Sybase主机上的 %SYBASE%\servername.cfg) 配置Sybase数 ...
- Intent七在属性之一:ComponentName
注:在<疯狂android讲义>中,此属性称为Component,官方文档中称为ComponentName. 1.The name of the component that should ...