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) ...
随机推荐
- 同域之下子iframe的DOM控制问题
new_file.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- mysqlslap: Error when connecting to server: 2001 Can't create UNIX socket (24) 解决方法
在用mysqlslap对mysql进行压力测试遇到mysqlslap: Error when connecting to server: 2001 Can't create UNIX socket ( ...
- [ller必读] LoveLive! 必备技能之 Python Pillow 自动处理截图
起因 喜欢的歌,静静地听:喜欢的人,远远的看.30天前,就是3月14号,我情不自禁地走近了<LoveLive!学院偶像祭>,这是我的第一张卡片(见下图).第二天也就是3月15日,海未生日了 ...
- dubbo之静态服务
有时候希望人工管理服务提供者的上线和下线,此时需将注册中心标识为非动态管理模式 <dubbo:registry address="10.20.141.150:9090" dy ...
- PAC学习理论:机器学习那些事
参考翻译,有大量删除和修改,如有异议,请拜访原文.一定要看英文原文!!!. 本文转载于:深度译文:机器学习那些事 英文[原题]A Few Useful Things to Know About Mac ...
- (转)基于Metronic的Bootstrap开发框架经验总结(9)--实现Web页面内容的打印预览和保存操作
http://www.cnblogs.com/wuhuacong/p/5147368.html 在前面介绍了很多篇相关的<Bootstrap开发框架>的系列文章,这些内容基本上覆盖到了我这 ...
- 微信jssdk图片上传
一.html页面如下: <div class="weui-cell"> <div class="weui-cell__hd"></ ...
- STM32F103 rtthread工程构建
目录 STM32F103 工程构建 1.基本情况 2.硬件连接 3.rtthread配置 4.点灯 5. 码云上git操作 STM32F103 工程构建 1.基本情况 RAM 20K ROM 64K ...
- eas之事件
选择事件 选择事件是在选择块发生变化后发出.table.addKDTSelectListener(new KDTSelectListener(){ public void tableSelect ...
- 26.bulk批量操作
主要知识点 1.bulk语法 2.bulk使用时的注意事项 3.bulk size 对es性能的影响 一.bulk语法 每一个操作要两个json串(delete操作除外),每个json串占一行 ...