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) ...
随机推荐
- Go Server Record
Centos Setup Go yum install glibc-headers gcc-c++ # 一键安装shadowsocks 1. wget --no-check-certificate - ...
- Md2All,把图片轻松上传到云图床,自动生成Markdown
内容目录 关于Md2AllMd2All的云图床效果直接把图片拖到编辑框截图,直接复制粘贴点图片图标选择图片注册七牛云帐号新建七牛云存储空间设置云图床密钥AK和SKBucketName和BucketDo ...
- 轻量数据库SQLiteDataBase的相关操作方法
一.查询操作: 查询操作比较复杂,主要有如下操作: db.rawQuery(String sql, String[] selectionArgs); db.query(String table, St ...
- 浅谈Overload和Override的区别
如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding).如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Over ...
- Content-Encoding与Content-Type的区别
RFC 2616 for HTTP 1.1 specifies how web servers must indicate encoding transformations using the Con ...
- C# tostring("0000000")
public string ConverNo(string str) { string result = ""; ]; ; i < chars.Length; i++) ch ...
- 将 GNOME 默认的界面切换动画功能关闭
gsettings set org.gnome.desktop.interface enable-animations false
- shell脚本—基础知识,变量
shell脚本本质: 编译型语言 解释型语言 shell编程基本过程 1.建立shell文件 2.赋予shell文件执行权限,使用chmod命令修改权限 3.执行shell文件 shell变量: sh ...
- Android 性能测试初探(四)
书接上文 Android 性能测试初探(三) 自从 cpu及内存后,GPU 这个词对于 PC 性能测试者也不陌生了,什么 3Dmax,安兔兔之类的第三方软件让 GPU 在移动端性能测试领域都知晓,但对 ...
- 在 Linux 下判断系统当前是否开启了超线程
转自: http://www.cnblogs.com/wjoyxt/p/4804293.html #lscpu Thread(s) per core: 2 Core(s) per socket: 6 ...