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风险飘过~~~ /************************************ ...
随机推荐
- 经验:Ubuntu 登陆 L2TP VPN
Ubuntu Linux 操作系统默认支持PPTP协议的VPN登陆,但是随着网络环境的复杂化,我们需要使用L2TP协议的VPN登陆,下面,我们只需要简单的几条命令即可登陆L2TP协议的VPN. ...
- Implement Trie (Prefix Tree) 解答
Question Implement a trie with insert, search, and startsWith methods. Note:You may assume that all ...
- libcurl 多线程使用注意事项 - Balder~专栏 - 博客频道 - CSDN.NET
libcurl 多线程使用注意事项 - Balder~专栏 - 博客频道 - CSDN.NET libcurl 多线程使用注意事项 分类: C/C++学习 2012-05-24 18:48 2843人 ...
- Windows SVN变化邮件通知(Python2.7实现)
1,新增文件post-commit.bat 内容: rem REPOS-PATH (the path to this repository) set REPOS=%1 rem REV (the num ...
- 有二级目录的IIS配置
当项目配置文件中配置了二级目录时,如下: <!--二级目录地址--> <add key="SecondCatalog" value="/hotel&qu ...
- Android 四大组件之 BroadcastReceiver
0 简介 BroadcastReceiver也就是“广播接收者”的意思,顾名思义,它就是用来接收来自系统和应用中的 广播. 在Android系统中,广播体现在方方面面,例 ...
- UIColor-Hex-Swift
// // UIColorExtension.swift // HEXColor // // Created by R0CKSTAR on 6/13/14. // Copyright (c) 2014 ...
- 【Java基础】foreach循环
从一个小程序说起: class lesson6foreach { public static void main(String[] args) { int array[]={2,3,1,5,4,6}; ...
- C#中操作刚导出的Excel,设置其为自动调整列宽
[问题] 用C#导出数据为excel,但是导出的数据中,不是自动调整列宽的: 希望变成这样的: [解决过程] 1.参考: 在C#里对excel文件的列宽进行操作 去试试: //auto adjust ...
- 使用react-native做一个简单的应用-02项目搭建与运行
下面我们开始着手去做这一个项目,因为初学不久就开始边学边做,所以有些地方设计不太合理.请大家多多包涵.0.0 下面来介绍截图中的三个文件夹, GuoKuApp:是我开发app的文件夹. GuoKuDB ...