HDU 3080 The plan of city rebuild(除点最小生成树)
题意 一个城市原来有l个村庄 e1条道路 又添加了n个村庄 e2条道路 后来后销毁了m个村庄 与m相连的道路也销毁了 求使全部未销毁村庄相互连通最小花费 不能连通输出what a pity!
还是非常裸的最小生成树 把销毁掉的标记下 然后prim咯 结果是无穷大就是不能连通的
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 300;
int mat[N][N], des[N], d[N], ans, n, m; void prim()
{
memset(d, 0x3f, sizeof(d));
int s = 0; while(des[s]) ++s;
d[s] = -1;
int cur = s, next = n;
for(int k = 1; k < n - m; ++k)
{
for(int i = 0; i < n; ++i)
{
if(des[i] || d[i] < 0) continue;
d[i] = min(d[i], mat[cur][i]);
if(d[i] < d[next]) next = i;
}
ans += d[next], d[next] = -1, cur = next, next = n;
}
} int main()
{
int cas, l, e1, e2, a, b, c;
scanf("%d", &cas);
while(cas--)
{
memset(mat, 0x3f, sizeof(mat));
memset(des, 0, sizeof(des));
scanf("%d %d", &l, &e1);
for(int i = 0; i < e1; ++i)
{
scanf("%d%d%d", &a, &b, &c);
if(c < mat[a][b]) mat[a][b] = mat[b][a] = c;
} scanf("%d %d", &n, &e2);
for(int i = 0; i < e2; ++i)
{
scanf("%d%d%d", &a, &b, &c);
if(c < mat[a][b]) mat[a][b] = mat[b][a] = c;
} n = n + l;
scanf("%d", &m);
for(int i = 0; i < m; ++i)
{
scanf("%d", &a);
des[a] = 1;
} ans = 0; prim();
if(ans < d[n]) printf("%d\n", ans);
else printf("what a pity!\n");
}
return 0;
}
The plan of city rebuild
ones should be destroyed. Then the officers have to make a new plan, now you , as the designer, have the task to judge if the plan is practical, which means there are roads(direct or indirect) between every two villages(of course the village has not be destroyed),
if the plan is available, please output the minimum cost, or output"what a pity!".
Each case contains three parts. The first part contains two integers l(0<l<100), e1, representing the original number of villages and roads between villages(the range of village is from 0 to l-1), then follows e1 lines, each line contains three integers a,
b, c (0<=a, b<l, 0<=c<=1000), a, b indicating the village numbers and c indicating the road cost of village a and village b . The second part first contains an integer n(0<n<100), e2, representing the number of new villages and roads(the range of village is
from l to l+n-1), then follows e2 lines, each line contains three integers x, y, z (0<=x, y<l+n, 0<=z<=1000), x, y indicating the village numbers and z indicating the road cost of village x and village y. The third part contains an integer m(0<m<l+n), representing
the number of deserted villages, next line comes m integers, p1,p2,…,pm,(0<=p1,p2,…,pm<l+n) indicating the village number.
Pay attention: if one village is deserted, the roads connected are deserted, too.
2
4 5
0 1 10
0 2 20
2 3 40
1 3 10
1 2 70
1 1
4 1 60
2
2 3
3 3
0 1 20
2 1 40
2 0 70
2 3
0 3 10
1 4 90
2 4 100
0
70
160
HDU 3080 The plan of city rebuild(除点最小生成树)的更多相关文章
- HDU 3080 The plan of city rebuild(prim和kruskal)
The plan of city rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- 2015 Multi-University Training Contest 1 hdu 5290 Bombing plan
Bombing plan Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- HDU 3757 Evacuation Plan DP
跟 UVa 1474 - Evacuation Plan 一个题,但是在杭电上能交过,在UVa上交不过……不知道哪里有问题…… 将施工队位置和避难所位置排序. dp[i][j] 代表前 i 个避难所收 ...
- hdu 5290 Bombing plan
http://acm.hdu.edu.cn/showproblem.php?pid=5290 题意: 一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需 ...
- HDU 4671 Backup Plan (2013多校7 1006题 构造)
Backup Plan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 2103 Family Plan
题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,the ...
- hdu 4671 Backup Plan(签到题)
错成那样,还以为是卡时间卡精度的变态题,结果就那么ac了= = 悔死我了 题意就不概述了,只要处理前两列即可.其中第一列顺序直接扫一遍,第二列要先处理较少的那几种.我是接着第一列用 head[] 继续 ...
- HDU 4671 Backup Plan 构造
负载是否平衡只与前两列有关,剩下的只要与前两列不重复就随便放. 第一列我们按1-n这样循环放,第二列每次找个数最少的那个服务器放. #include <cstdio> #include & ...
- HDU 4081 Qin Shi Huang's National Road System 最小生成树+倍增求LCA
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4081 Qin Shi Huang's National Road System Time Limit: ...
随机推荐
- React脚手架
所谓脚手架,是指一套基础的开发环境,你只需要简单的配置或者无需配置,就可以直接开发自己的业务代码,而无需劳神在搭建环境上. 比较出名的就是facebook自己出的的脚手架:create-react-a ...
- 使用Faric+Git进行分布式代码管理
Fabric是一个Python库,可以通过SSH在多个host上批量执行任务. 可以通过编写任务脚本,然后通过Fabric在本地就可以使用SSH在大量远程服务器上自动运行. 这些功能非常适合应用的自动 ...
- Accessing Report Server using Report Server Web Service - Microsoft SQL Server 2008R2
Today I am going to write about how to access SQL Server Report Server through Report Server Web ser ...
- Netty4详解三:Netty架构设计(转)
http://blog.csdn.net/suifeng3051/article/details/28861883?utm_source=tuicool&utm_medium=referral ...
- web.xml文件中配置mime下载文件类型(转)
转自:http://5aijava.iteye.com/blog/166600 TOMCAT在默认情况下下载.rar的文件是把文件当作text打开,以至于IE打开RAR文件为乱码,如果遇到这种情况时不 ...
- 倍福TwinCAT(贝福Beckhoff)应用教程12.1 TwinCAT控制松下伺服 连接和试运行
首先是用松下伺服自带的软件可以测试运行(驱动器,电机都连接好,然后用USB线连接到松下伺服驱动器的X1口),打开调试软件会自动提示连接到伺服 一般需要对驱动器清除绝对值编码器数据(驱动器可能报错4 ...
- 【React Native开发】React Native控件之Image组件解说与美团首页顶部效果实例(10)
),React Native技术交流4群(458982758),欢迎各位大牛,React Native技术爱好者增加交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! Im ...
- Split Animation Clip From FBX and Multiply Mode Sprite
Use Script To Creat 2D Animation Clip From Multiply Mode Sprite 很多时候美工拿过来的一张序列帧图片,我们需要转换成 Multiply M ...
- Django开发博客(七)——markdown优化
背景 上一次把markdown集成之后.发现还是有非常多问题. 这次须要做一些优化. 1.markdown与普通文本的差别显示. 2.添加点击量的统计 3.加入名片卡的滑动 版本号相关 操作系统:Ma ...
- jsoup爬虫简书首页数据做个小Demo
代码地址如下:http://www.demodashi.com/demo/11643.html 昨天LZ去面试,遇到一个大牛,被血虐一番,发现自己基础还是很薄弱,对java一些原理掌握的还是不够稳固, ...